MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / namespace

Function namespace

pkg/errors/pkg_util.go:34–44  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
34func 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}

Callers 3

FromHTTPStatusCodeFunction · 0.85
defineFunction · 0.85
NewFunction · 0.85

Calls 3

TrimPrefixMethod · 0.80
CallerMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected