Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created September 20, 2011 01:12
Show Gist options
  • Save kylelemons/1228069 to your computer and use it in GitHub Desktop.
Save kylelemons/1228069 to your computer and use it in GitHub Desktop.
Get the calling function's package
func GetMyCaller() (pkg, fun string) {
pc, _, _, ok := runtime.Caller(2) // get my(0) caller(1)'s caller(2)
if !ok { return "", "" }
caller := strings.SplitN(runtime.FuncForPC(pc).Name(), ".", 2)
return caller[0], caller[1]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment