namespace is called when errors are defined. It returns the package path of the caller (skipping the first frames of the call stack) and makes it relative (so for example: pkg/errors).
(skip int)
| 32 | // It returns the package path of the caller (skipping the first frames of the call stack) |
| 33 | // and makes it relative (so for example: pkg/errors). |
| 34 | func namespace(skip int) string { |
| 35 | pc, _, _, ok := runtime.Caller(skip) |
| 36 | if !ok { |
| 37 | panic("could not determine source of error") |
| 38 | } |
| 39 | fun := runtime.FuncForPC(pc).Name() |
| 40 | slashIdx := strings.LastIndexByte(fun, '/') |
| 41 | dotIdx := strings.IndexByte(fun[slashIdx:], '.') |
| 42 | pkg := fun[:slashIdx+dotIdx] |
| 43 | return strings.TrimPrefix(pkg, pkgPrefix) |
| 44 | } |
no test coverage detected