Is there a way to get the source code filename and line number in Go?

后端 未结 1 712
长情又很酷
长情又很酷 2021-01-20 01:33

In C/C++ you can use __FILE__ and __LINE__ to get access to the current file and line number.

Does Go provide something similar?

相关标签:
1条回答
  • 2021-01-20 02:31

    Indeed it does:

    http://golang.org/pkg/runtime/#Caller

    runtime.Caller can also be used to get the file name/line number of calling functions, too.

    0 讨论(0)
提交回复
热议问题