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

when the package name is different form import name it can't work? #40

Open
zboya opened this issue Jun 14, 2016 · 1 comment
Open

when the package name is different form import name it can't work? #40

zboya opened this issue Jun 14, 2016 · 1 comment

Comments

@zboya
Copy link

zboya commented Jun 14, 2016

package main

import (
    "net/http"

    "github.com/googollee/go-socket.io"
    "listome.com/log"
)

func main() {
    server, err := socketio.NewServer(nil)
    if err != nil {
        log.Fatal(err)
    }
    server.On("connection", func(so socketio.Socket) {
        log.Info("on connection")
        so.Join("paint_game")

        so.On("paint", func(msg string) {
            // log.Info("painting:", msg)
            log.Info("broadcast:", so.BroadcastTo("paint_game", "painting", msg))
        })
        so.On("disconnection", func() {
            log.Info("on disconnect")
        })
    })
    server.On("error", func(so socketio.Socket, err error) {
        log.Error("error:", err)
    })

    http.Handle("/socket.io/", server)
    http.Handle("/", http.FileServer(http.Dir("./")))
    log.Info("Serving at localhost:5000...")
    log.Fatal(http.ListenAndServe(":5000", nil))

}

godef -f main.go 'socketio.NewServer'
parseLocalPackage error: no more package files found
godef: no declaration found for socketio.NewServer

when I add import name,

package main

import (
    "net/http"

    socketio "github.com/googollee/go-socket.io"
    "listome.com/log"
)

func main() {
    server, err := socketio.NewServer(nil)
    if err != nil {
        log.Fatal(err)
    }
    server.On("connection", func(so socketio.Socket) {
        log.Info("on connection")
        so.Join("paint_game")

        so.On("paint", func(msg string) {
            // log.Info("painting:", msg)
            log.Info("broadcast:", so.BroadcastTo("paint_game", "painting", msg))
        })
        so.On("disconnection", func() {
            log.Info("on disconnect")
        })
    })
    server.On("error", func(so socketio.Socket, err error) {
        log.Error("error:", err)
    })

    http.Handle("/socket.io/", server)
    http.Handle("/", http.FileServer(http.Dir("./")))
    log.Info("Serving at localhost:5000...")
    log.Fatal(http.ListenAndServe(":5000", nil))

}

godef -f main.go 'socketio.NewServer'
/home/lstbao/work/listomego/src/github.com/googollee/go-socket.io/server.go:17:6

It can work well.

@rogpeppe
Copy link
Owner

Interesting. Running godef on the NewServer instance in the source (cat main.go | def -o 150) works OK but when specifying the expression on the command line, it does not.

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