Home > Backend Development > Golang > 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
Release: 2024-02-05 23:27:12
forward
667 people have browsed it

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template