location

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2020 License: BSD-3-Clause Imports: 6 Imported by: 1

Documentation

Overview

Package location provides a way to retrieve the current location in code. This can be used in logging or monitoring. Passing an offset helps hiding calling wrappers.

l1 := location.Here()
l2 := location.At(5)
id := location.At(2).ID
code := location.At(2).Code("ERR")
stack := location.HereDeep(5)

Internal caching fastens retrieval after first call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Location

type Location struct {
	ID      string
	Package string
	File    string
	Func    string
	Line    int
}

Location contains the formatted ID and the details of one location.

func At

func At(offset int) Location

At returns the location at the given offset.

func Here

func Here() Location

Here return the current location.

func (Location) Code

func (l Location) Code(prefix string) string

Code returns returns a location based code.

type Stack

type Stack []Location

Stack contains a number of locations of a call stack.

func HereDeep

func HereDeep(depth int) Stack

HereDeep returns the current callstack until the given depth.

func (Stack) String

func (s Stack) String() string

String returns a string representation of the stack.

Jump to

Keyboard shortcuts

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