DRYな備忘録

Don't Repeat Yourself.

【Go言語】メモ:runtime.Caller

runtime.Caller

runtime - The Go Programming Language

func Caller(skip int) (pc uintptr, file string, line int, ok bool)

Callerはgoroutineのスタックから呼び出された関数のファイルと行数に関する情報をレポートします. 引数skipは、スタックフレームをさかのぼる数で、0が与えられた場合、runtime.Callerを呼び出した自身のcallerを指します. (歴史的な理由により、runtime.Callerruntime.Callersの引数skipは意味が違うので注意です.) 返り値はそれぞれ該当する呼び出し元の、プログラムカウンタ、ファイル名、行数です. 第四返り値のokは、これらの情報が取得できなかった場合にfalseとなります. *1

しらべた用語

しらべた英単語

*1:Caller reports file and line number information about function invocations on the calling goroutine's stack. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of Caller. (For historical reasons the meaning of skip differs between Caller and Callers.) The return values report the program counter, file name, and line number within the file of the corresponding call. The boolean ok is false if it was not possible to recover the information.