Skip to content

Instantly share code, notes, and snippets.

@jeanbza
Last active September 20, 2018 20:15
Show Gist options
  • Save jeanbza/d53d4283c7217982426eb5ac56dd0800 to your computer and use it in GitHub Desktop.
Save jeanbza/d53d4283c7217982426eb5ac56dd0800 to your computer and use it in GitHub Desktop.
callers
func MyCallers() []string {
// we get the callers as uintptrs
fpcs := make([]uintptr, 1024)
n := runtime.Callers(-1, fpcs)
if n == 0 {
return []string{"I don't know your caller! What the heck.."}
}
var callers []string
for _, c := range fpcs {
// get the info of the actual function that's in the pointer
fun := runtime.FuncForPC(c-1)
if fun == nil {
// we're done
break
}
callers = append(callers, fun.Name()+"\n")
}
return callers
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment