本文介绍了有没有办法在Go中获取源代码文件名和行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C / C ++中,您可以使用 __ FILE __ __ LINE __ 来访问当前文件和行号。

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

Go是否提供类似的东西?

Does Go provide something similar?

推荐答案

runtime.Caller 也可用于获取文件名/线路号码的呼叫功能。

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

这篇关于有没有办法在Go中获取源代码文件名和行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:50
查看更多