Created
November 11, 2021 09:26
-
-
Save tsyber1an/155300cc866e6a27a7e650b246cf73b5 to your computer and use it in GitHub Desktop.
runtime.Caller example
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
package main | |
import ( | |
"fmt" | |
"runtime" | |
) | |
func foo() { | |
_, file, no, ok := runtime.Caller(1) | |
if ok { | |
fmt.Printf("called from %s#%d\n", file, no) | |
} | |
} | |
func main() { | |
foo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment