caller returns a string containing filename and line number of the nearest function invocation on the calling goroutine's stack, after skipping functions marked as helper functions. If no stack information is available, it returns "?:?".
()
| 48 | // after skipping functions marked as helper functions. |
| 49 | // If no stack information is available, it returns "?:?". |
| 50 | func caller() string { |
| 51 | for i := 1; ; i++ { |
| 52 | // NOTE(kr): This is quadratic in the number of frames we |
| 53 | // ultimately have to skip. Consider using Callers instead. |
| 54 | pc, file, line, ok := runtime.Caller(i) |
| 55 | if !ok { |
| 56 | return "?:?" |
| 57 | } |
| 58 | if !isHelper(runtime.FuncForPC(pc).Name()) { |
| 59 | return filepath.Base(file) + ":" + strconv.Itoa(line) |
| 60 | } |
| 61 | } |
| 62 | } |