eruntime

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const Is64Bit = math.MaxInt64 == math.MaxInt

Is64Bit is true on 64-bit systems. (In 2022, that's nearly everything).

Variables

This section is empty.

Functions

func ThisDir

func ThisDir() string

ThisDir returns the directory of it's caller.

func ThisFile

func ThisFile() string

ThisFile returns the file of it's caller.

func ThisFileLine

func ThisFileLine() (file string, line int)

func TrimFunction

func TrimFunction(s string) string

TrimFunction trims a function path containing "efronlicht/estd", making it start with "estd". EG, "users/efron/go/src/gitlab.com/efronlicht/estd/parse/IPv4" => "estd/parse.IPv4". this looks nice, but has a runtime cost. use the build tag "eruntime_notrim" to disable it

Types

type FuncInfo

type FuncInfo struct {
	// Function name, obtained via runtime.FuncForPC.Name().
	Function string
	// Filename, including path.
	File  string
	Label string // optional label
	Line  int
}

FuncInfo is limited function metadata, often embedded in logs. It has a handy String() which looks like this: Get a FuncInfo with NamedFunc() or Caller().

func Caller

func Caller(skip int) *FuncInfo

Caller reports the file, line number, and name of the function skip levels up the stack. skip=0 is the caller of Caller:

func a() { return fmt.Println(Caller(1))}
func b() { a() } // will print info about b(), not a().

func LabeledCaller

func LabeledCaller(name string, skip int) *FuncInfo

func (*FuncInfo) Base

func (c *FuncInfo) Base() string

func (*FuncInfo) MarshalLogObject

func (fi *FuncInfo) MarshalLogObject(oe zapcore.ObjectEncoder) error

func (*FuncInfo) MarshalZerologObject

func (fi *FuncInfo) MarshalZerologObject(e *zerolog.Event)

func (*FuncInfo) Package

func (c *FuncInfo) Package() string

func (*FuncInfo) String

func (c *FuncInfo) String() string

type StackSlice

type StackSlice []*FuncInfo

StackSlice is a []*FuncInfo that nicely formats for fmt.Stringer, zapcore.ArrayMarshaler, and zerolog.ZerologArrayMarshaler.

func Callers

func Callers(skip, n int) (callers StackSlice)

Callers obtains a miniature stack trace of at most n elements starting at skip via runtime.Callers(skip+1). It returns at most n elements, but may return fewer, or even zero (if skip is larger than the stack).

func (StackSlice) MarshalLogArray

func (s StackSlice) MarshalLogArray(ae zapcore.ArrayEncoder) error

func (StackSlice) MarshalZerologArray

func (s StackSlice) MarshalZerologArray(a *zerolog.Array)

func (StackSlice) String

func (s StackSlice) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL