godef
godef copied to clipboard
when the package name is different form import name it can't work?
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.
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.