Created
September 20, 2011 01:12
-
-
Save kylelemons/1228069 to your computer and use it in GitHub Desktop.
Get the calling function's package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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