有没有办法在Go中获取源代码文件名和行号? [英] Is there a way to get the source code filename and line number in Go?

查看:199
本文介绍了有没有办法在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?

推荐答案

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

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆