controlflow

package
v1.97.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All added in v1.46.0

func All(ops ...func() bool) (r bool)

func Checkerr2Exit added in v1.55.0

func Checkerr2Exit(tag string, err error)

func Checkerr2Raise added in v1.55.0

func Checkerr2Raise(tag string, err error)

The equivalent of !!! operator in Go2

func Either added in v1.46.0

func Either(ops ...func() bool) (r bool)

func RaiseCause added in v1.81.0

func RaiseCause(forward_trace *trace.Forwardtrace, first_backtrace_point *trace.BacktracePoint)

Example usage:

controlflow.RaiseCause(tracer.GetForwardtrace(), trace.BacktracePointf("123123", "the cause"))
controlflow.RaiseCause(nil, trace.BacktracePointf("123123", "the cause"))

Sometimes, some function want to raise the cause, but it's too tedious to pass the tracer in it; in this case, the function may raise it with nil forwardtrace (and it's okay), and then the user of it will catch the event, and set actual forwardtrace directly. Example, inside such a function:

controlflow.RaiseCause(nil, trace.BacktracePointf("123123", err.Error()))

And then at first interception point:

event.Forwardtrace = tracer.GetForwardtrace()

Types

type BacktraceDomainChain added in v1.81.0

type BacktraceDomainChain []*trace.BacktracePoint

First element is most specific, last ones are least specific - this is the inverse of forwardtrace tags;

func (*BacktraceDomainChain) GetIdsChainLVA added in v1.84.0

func (d *BacktraceDomainChain) GetIdsChainLVA() []byte

Used for efficient matching of Id sequences using bytes.Contains() and bytes.HasPrefix(). See also trace.EncodeLVA()

func (BacktraceDomainChain) Last added in v1.81.0

E.g. to get the one before last, use Last(-2); The purpose is to easily get the last thing. Also used internally

type CtxValueAccessor added in v1.86.0

type CtxValueAccessor[T any] struct {
	Key                     any
	ConstructIfMissing_Func func() T
}

func (*CtxValueAccessor[T]) GetObjectFromCtx added in v1.86.0

func (a *CtxValueAccessor[T]) GetObjectFromCtx(ctx context.Context) (object T)

func (*CtxValueAccessor[T]) SetObjectToCtx added in v1.86.0

func (a *CtxValueAccessor[T]) SetObjectToCtx(parent_ctx context.Context, object any) (new_ctx context.Context)

type Event added in v1.81.0

type Event struct {
	RetryAttemptNb int `json:"-"`
	Forwardtrace   *trace.Forwardtrace
	Backtrace      FullBacktrace
}

func NewEvent added in v1.81.0

func NewEvent(forward_trace *trace.Forwardtrace, first_backtrace_point *trace.BacktracePoint) *Event

Example usage: controlflow.RaiseCause(tracer.GetForwardtrace(), trace.BacktracePointf("123123", "the cause")) controlflow.RaiseCause(nil, trace.BacktracePointf("123123", "the cause"))

func Retry added in v1.51.0

func Retry(f_do func() (err any), f_failure func(e *Event) (end bool)) (e *Event)

Allows to try and retry an operation several times.

func Try

func Try(f func() (err any)) (e *Event)

func (*Event) Catch added in v1.81.0

func (e *Event) Catch(f func(e *Event)) *Event

func (*Event) ContainAndWrap added in v1.84.0

func (existing_event *Event) ContainAndWrap(added_backtrace_point *trace.BacktracePoint) *Event

Creates new domain chain on the backtrace

func (*Event) Error added in v1.81.0

func (e *Event) Error() string

func (*Event) JSON added in v1.83.0

func (e *Event) JSON() []byte

func (*Event) OK added in v1.81.0

func (e *Event) OK(f func()) *Event

func (*Event) Reraise added in v1.81.0

func (existing_event *Event) Reraise(added_backtrace_point *trace.BacktracePoint)

func (*Event) Serk added in v1.83.0

func (e *Event) Serk() string

func (*Event) String added in v1.81.0

func (e *Event) String() string

func (*Event) Wrap added in v1.81.0

func (existing_event *Event) Wrap(added_backtrace_point *trace.BacktracePoint) *Event

Appends the event with additional backtrace point - just like the Reraise(), but without side effects

type FullBacktrace added in v1.81.0

type FullBacktrace []*BacktraceDomainChain

First element is most specific, last ones are least specific - this is the inverse of forwardtrace tags;

func (FullBacktrace) GetIdsChainLVA added in v1.84.0

func (b FullBacktrace) GetIdsChainLVA() []byte

Used for efficient matching of Id sequences using bytes.Contains() and bytes.HasPrefix(). See also trace.EncodeLVA()

func (FullBacktrace) Last added in v1.81.0

func (b FullBacktrace) Last(neg_i int) *BacktraceDomainChain

E.g. to get the one before last, use Last(-2); The purpose is to easily get the last thing. Also used internally

type KeyedTable

type KeyedTable[T comparable] map[T]func() int // -1 break/complete

func (KeyedTable[T]) Sequence

func (t KeyedTable[T]) Sequence(keys ...T)

func (KeyedTable[T]) Switch

func (t KeyedTable[T]) Switch(primary, default_ T)

type MatchCase

type MatchCase struct {
	Match func() int // 0 no match, 1 match, -1 break
	Then  func() int
}

type MatchTable

type MatchTable []MatchCase

func (MatchTable) Match

func (t MatchTable) Match()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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