Skip to content

Instantly share code, notes, and snippets.

@dgryski
Created January 13, 2017 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgryski/31ef7c8d40f804ab1d91f0c47728e928 to your computer and use it in GitHub Desktop.
Save dgryski/31ef7c8d40f804ab1d91f0c47728e928 to your computer and use it in GitHub Desktop.
guru
<dgryski@kamek[w] \ʕ◔ϖ◔ʔ/ > cat main.go
package main
import "log"
type X struct {
body string
}
type Message interface {
Body() string
}
type LoggableMessage interface {
log()
}
func (x *X) Body() string {
return x.body
}
func (x *X) log() {
log.Printf("logging body: %q\n", x.body)
}
func send(m Message) {
log.Printf("sending: %v", m.Body())
if l, ok := m.(LoggableMessage); ok {
l.log()
}
}
func main() {
x := X{body: "hello, world"}
send(&x)
}
<dgryski@kamek[w] \ʕ◔ϖ◔ʔ/ > guru -scope github.com/dgryski/w callers main.go:#193
/home/dgryski/Dropbox/GITS/gocode/src/github.com/dgryski/w/main.go:21:13: (*github.com/dgryski/w.X).log is called from these 1 sites:
/home/dgryski/Dropbox/GITS/gocode/src/github.com/dgryski/w/main.go:29:8: dynamic method call from github.com/dgryski/w.send
<dgryski@kamek[w] \ʕ◔ϖ◔ʔ/ >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment