ctx

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Background

func Background() (C, CancelFunc)

func Cause

func Cause(c C) error

func GetTracking

func GetTracking(c C) string

func NewError

func NewError(c C, err error) error

Obsolete: use WrapError

func NewErrorf

func NewErrorf(c C, f string, args ...any) error

creates a new error using the given format and argument if any argument is an error, it will be wrapped as per fmt.Errorf() the error is then given a stack trace and context unless it already has one

func RangeTag

func RangeTag(c C, fn func(k string, json JSON) error) error

scan the chain of context for tags, call the function on each of them, parents first

func Span

func Span(c C, name string) (C, CancelFunc)

TEMP

func WithCancel

func WithCancel(c C) (C, CancelFunc)

func WrapError

func WrapError(c C, err error) error

if the given error is nil, returns nil. Otherwise check if it already was wrapped into a ctx.Error and wrap it if not

Types

type C

type C context.Context

just an alias, so you can type `c ctx.C` instead of `ctx context.Context`

func TODO

func TODO() C

func WithDeadline

func WithDeadline(c C, t time.Time) (C, func())

func WithTag

func WithTag(c C, key string, val any) C

Append the given key/val pair to the context Note(oha): if the same key is added twice, it will be found twice later with the Range

func WithTimeout

func WithTimeout(c C, d time.Duration) (C, func())

func WithTracking

func WithTracking(c C, suggest string) C

create a new tracking id embedded in the context, the suggested id can be used if valid, otherwise a new id is created

type CancelFunc

type CancelFunc context.CancelCauseFunc

type Error

type Error struct {
	Stack []string
	C     C
	// contains filtered or unexported fields
}

a generic error which contains the stack trace

func (Error) Is

func (this Error) Is(err error) bool

func (Error) Unwrap

func (err Error) Unwrap() error

type JSON

type JSON []byte

just a []byte, but marshal and unmarshal like json.RawMessage and it is printed as string in logs, win win

func (JSON) MarshalJSON

func (this JSON) MarshalJSON() ([]byte, error)

func (JSON) String

func (this JSON) String() string

func (*JSON) UnmarshalJSON

func (this *JSON) UnmarshalJSON(j []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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