Created
February 15, 2017 06:37
-
-
Save YanhaoYang/5889af8df093663063b5a4ad7b0b4feb to your computer and use it in GitHub Desktop.
Print caller info
This file contains hidden or 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
package main | |
import ( | |
"fmt" | |
"path" | |
"runtime" | |
) | |
func callerInfo() string { | |
function, file, line, _ := runtime.Caller(0) | |
return fmt.Sprintf("%s@%s:%d", runtime.FuncForPC(function).Name(), path.Base(file), line) | |
} | |
func main() { | |
fmt.Println(callerInfo()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment