[golang学习记录-20220227-001] Golang获取调用本函数的语句所在的文件与行号
import (
"fmt"
"runtime"
)
func main() {
selectUser()
}
func selectUser() {
_, file, line, _ := runtime.Caller(1)
fmt.Println(file, line)
}
此时会打印出该文件的绝对路径+文件名,及 selectUser()所在的行号
每天记录一点点!
...
原创
2022-02-27 23:21:38 ·
454 阅读 ·
0 评论