Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't go to definition #554

Closed
wingedkiwi opened this issue Sep 12, 2014 · 1 comment
Closed

Can't go to definition #554

wingedkiwi opened this issue Sep 12, 2014 · 1 comment

Comments

@wingedkiwi
Copy link

Hi!

I am learning go right now and I was playing with this example from an oauth2 package: https://github.com/RangelReale/osin/blob/master/example/simple/simple.go

I noticed that the autocompletion of the variable server works, but strangely the "go to definition" doesn't. Whereas in other projects like LiteIde has no problems with finding the definitions.

This problem keeps me from using Sublime as an IDE although its an awesome editor.

I am using mac os x 10.9.4, ST 3

Chi

package main

// Open url in browser:
// http://localhost:14000/app

import (
    "fmt"
    "github.com/RangelReale/osin"
    "github.com/RangelReale/osin/example"
    "net/http"
    "net/url"
)

func main() {
    cfg := osin.NewServerConfig()
    cfg.AllowGetAccessRequest = true
    cfg.AllowClientSecretInParams = true

    server := osin.NewServer(cfg, example.NewTestStorage())
    server.HandleAuthorizeRequest(w, r)

    // Authorization code endpoint
    http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
        resp := server.NewResponse()
        defer resp.Close()
        if ar := server.HandleAuthorizeRequest(resp, r); ar != nil {
            if !example.HandleLoginPage(ar, w, r) {
                return
            }
            ar.Authorized = true
            server.FinishAuthorizeRequest(resp, r, ar)
        }
        if resp.IsError && resp.InternalError != nil {
            fmt.Printf("ERROR: %s\n", resp.InternalError)
        }
        osin.OutputJSON(resp, w, r)
    })

    // Access token endpoint
    http.HandleFunc("/token", func(w http.ResponseWriter, r *http.Request) {
        resp := server.NewResponse()
        defer resp.Close()

        if ar := server.HandleAccessRequest(resp, r); ar != nil {
            ar.Authorized = true
            server.FinishAccessRequest(resp, r, ar)
        }
        if resp.IsError && resp.InternalError != nil {
            fmt.Printf("ERROR: %s\n", resp.InternalError)
        }
        osin.OutputJSON(resp, w, r)
    })

    // Information endpoint
    http.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) {
        resp := server.NewResponse()
        defer resp.Close()

        if ir := server.HandleInfoRequest(resp, r); ir != nil {
            server.FinishInfoRequest(resp, r, ir)
        }
        osin.OutputJSON(resp, w, r)
    })

    // Application home endpoint
    http.HandleFunc("/app", func(w http.ResponseWriter, r *http.Request) {
        w.Write([]byte("<html><body>"))
        w.Write([]byte(fmt.Sprintf("<a href=\"/authorize?response_type=code&client_id=1234&state=xyz&scope=everything&redirect_uri=%s\">Login</a><br/>", url.QueryEscape("http://localhost:14000/appauth/code"))))
        w.Write([]byte("</body></html>"))
    })

    // Application destination - CODE
    http.HandleFunc("/appauth/code", func(w http.ResponseWriter, r *http.Request) {
        r.ParseForm()

        code := r.Form.Get("code")

        w.Write([]byte("<html><body>"))
        w.Write([]byte("APP AUTH - CODE<br/>"))

        if code != "" {
            jr := make(map[string]interface{})

            // build access code url
            aurl := fmt.Sprintf("/token?grant_type=authorization_code&client_id=1234&client_secret=aabbccdd&state=xyz&redirect_uri=%s&code=%s",
                url.QueryEscape("http://localhost:14000/appauth/code"), url.QueryEscape(code))

            // if parse, download and parse json
            if r.Form.Get("doparse") == "1" {
                err := example.DownloadAccessToken(fmt.Sprintf("http://localhost:14000%s", aurl),
                    &osin.BasicAuth{"1234", "aabbccdd"}, jr)
                if err != nil {
                    w.Write([]byte(err.Error()))
                    w.Write([]byte("<br/>"))
                }
            }

            // show json error
            if erd, ok := jr["error"]; ok {
                w.Write([]byte(fmt.Sprintf("ERROR: %s<br/>\n", erd)))
            }

            // show json access token
            if at, ok := jr["access_token"]; ok {
                w.Write([]byte(fmt.Sprintf("ACCESS TOKEN: %s<br/>\n", at)))
            }

            w.Write([]byte(fmt.Sprintf("FULL RESULT: %+v<br/>\n", jr)))

            // output links
            w.Write([]byte(fmt.Sprintf("<a href=\"%s\">Goto Token URL</a><br/>", aurl)))

            cururl := *r.URL
            curq := cururl.Query()
            curq.Add("doparse", "1")
            cururl.RawQuery = curq.Encode()
            w.Write([]byte(fmt.Sprintf("<a href=\"%s\">Download Token</a><br/>", cururl.String())))
        } else {
            w.Write([]byte("Nothing to do"))
        }

        w.Write([]byte("</body></html>"))
    })

    http.ListenAndServe(":14000", nil)
}
@dlclark
Copy link

dlclark commented Dec 1, 2014

Margo (the backend) currently doesn't support this level of Go To Definition, but I believe this is fixed by my changes in #571.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants