Jeroen Dirks
Jeroen Dirks

Reputation: 7887

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

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

Does Go provide something similar?

Upvotes: 4

Views: 1849

Answers (1)

Roxy Light
Roxy Light

Reputation: 5147

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.

Upvotes: 9

Related Questions