fuel

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2021 License: MPL-2.0 Imports: 15 Imported by: 1

README

FUeL.go

Frequently UsEd Libraries for GOlang – the "juice" which powers Golang applications with drive.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtStateToString

func FmtStateToString(fs fmt.State) string

FmtStateToString converts $fs to its fmt.Printf() representation (see unit tests).

func FormatNonFormatter

func FormatNonFormatter(fs fmt.State, verb rune, nonFormatter interface{})

FormatNonFormatter forwards $fs and $verb to $nonFormatter.Format() if $nonFormatter is a fmt.Formatter. Otherwise it formats $nonFormatter via fmt.Fprintf() as specified by $fs and $verb.

func GetStack

func GetStack(skip int) errors.StackTrace

GetStack returns a complete errors.StackTrace of the calling goroutine without GetStack itself and $skip additional frames at the top.

func SignalsToContext

func SignalsToContext(ctx context.Context, signals ...os.Signal) (child context.Context, reason <-chan os.Signal)

SignalsToContext derives $child from $ctx and cancels it on one of $signals. The exact signal (or nil on $ctx cancellation) is forwarded to $reason. $signals will be handled by SignalsToContext until $ctx cancellation to prevent firing of default handlers. Cancel $ctx not to leak goroutines!

Types

type AdvancedError

type AdvancedError struct {
	Err   error
	Stack errors.StackTrace
}

AdvancedError is a feature-rich error wrapper.

func (AdvancedError) Cause

func (ae AdvancedError) Cause() error

func (AdvancedError) Error

func (ae AdvancedError) Error() string

func (AdvancedError) Format

func (ae AdvancedError) Format(fs fmt.State, verb rune)

Format appends the stack on %+v and %v.

func (AdvancedError) MarshalJSON

func (ae AdvancedError) MarshalJSON() ([]byte, error)

func (AdvancedError) MarshalText

func (ae AdvancedError) MarshalText() (text []byte, err error)

func (AdvancedError) StackTrace

func (ae AdvancedError) StackTrace() errors.StackTrace

func (AdvancedError) String

func (ae AdvancedError) String() string

func (AdvancedError) Unwrap

func (ae AdvancedError) Unwrap() error

type Causer

type Causer interface {
	Cause() error
}

type ElasticQueue

type ElasticQueue struct {
	// contains filtered or unexported fields
}

ElasticQueue runs enqueued tasks immediately until context cancellation.

func NewElasticQueue

func NewElasticQueue(ctx context.Context) *ElasticQueue

NewElasticQueue creates a new ElasticQueue. $ctx is forwarded to Enqueue()d tasks.

func (*ElasticQueue) Enqueue

func (eq *ElasticQueue) Enqueue(_ int64, f func(context.Context))

func (*ElasticQueue) Wait

func (eq *ElasticQueue) Wait()

type ErrorGroup

type ErrorGroup struct {
	// contains filtered or unexported fields
}

ErrorGroup is a more feature-rich version of golang.org/x/sync/errgroup.Group:

* enforces usage of ErrorWithStack, not just error * assembles stack across goroutines * context is forwarded to tasks * optional concurrency limit * stops on context cancellation

func NewErrorGroup

func NewErrorGroup(ctx context.Context, concurrency int64) *ErrorGroup

NewErrorGroup creates a new ErrorGroup. $ctx is forwarded to tasks. $concurrency < 1 means infinite.

func (*ErrorGroup) Go

func (eg *ErrorGroup) Go(weight int64, f func(context.Context) ErrorWithStack)

func (*ErrorGroup) Wait

func (eg *ErrorGroup) Wait() ErrorWithStack

type ErrorWithStack

type ErrorWithStack interface {
	error
	StackTracer
}

func AttachStackToError

func AttachStackToError(err error, skip int) ErrorWithStack

AttachStackToError attaches a complete errors.StackTrace of the calling goroutine to $err if needed, without AttachStackToError itself and $skip additional frames at the top.

type Formatable

type Formatable struct {
	// Output is the actual writer.
	Output io.Writer
	// Error is the first write error.
	Error ErrorWithStack

	Wid     int
	Prec    int
	HasWid  bool
	HasPrec bool
	Flags   map[int]struct{}
}

Formatable may be used instead of fmt.Fprintf() for exactly one fmt.Formatter.

func (*Formatable) Flag

func (f *Formatable) Flag(c int) bool

func (*Formatable) Precision

func (f *Formatable) Precision() (int, bool)

func (*Formatable) Width

func (f *Formatable) Width() (int, bool)

func (*Formatable) Write

func (f *Formatable) Write(b []byte) (n int, err error)

type LimitedQueue

type LimitedQueue struct {
	// contains filtered or unexported fields
}

LimitedQueue runs enqueued tasks with limited concurrency in FIFO order until context cancellation.

func NewLimitedQueue

func NewLimitedQueue(ctx context.Context, concurrency int64) *LimitedQueue

NewLimitedQueue creates a new LimitedQueue which runs $concurrency tasks at a time. $ctx is forwarded to Enqueue()d tasks.

func (*LimitedQueue) Enqueue

func (lq *LimitedQueue) Enqueue(weight int64, f func(context.Context))

func (*LimitedQueue) Wait

func (lq *LimitedQueue) Wait()

type RunQueue

type RunQueue interface {
	// Enqueue enqueues the task $f for being run ASAP. $f is counted as $weight item(s).
	Enqueue(weight int64, f func(context.Context))
	// Wait waits for all Enqueue()d tasks to finish.
	Wait()
}

type StackTracer

type StackTracer interface {
	StackTrace() errors.StackTrace
}

type Unwrapper

type Unwrapper interface {
	Unwrap() error
}

Jump to

Keyboard shortcuts

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