Home  >  Article  >  Backend Development  >  Is there a way in Go to get the source code filename and line number?

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

WBOY
WBOYforward
2024-02-05 23:27:12560browse

Go 有没有办法获取源代码文件名和行号?

Question content

In C/C, you can use __FILE__ and __LINE__ to access the current File and line numbers.

Does Go offer something similar?


Correct answer


Indeed:

https://www.php.cn/link/c0e0b7080b94f208328b48cbea738d86

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

The above is the detailed content of Is there a way in Go to get the source code filename and line number?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete