grace

package module
v0.0.0-...-1486261 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2023 License: MIT Imports: 7 Imported by: 1

README

grace

workflow badge Go Reference

An elegant golang utils library

优雅,永不过时

Donation

View https://guoyk.xyz/donation

Credits

Guo Y.K., MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(tasks ...Task) (err error)

func DoContext

func DoContext(ctx context.Context, tasks ...ContextTask) (err error)

func Extract

func Extract[T any](ctx context.Context) (out T, ok bool)

func Guard

func Guard(err *error)

func IgnoreEOF

func IgnoreEOF(err *error)

func Inject

func Inject[T any](ctx context.Context, v T) context.Context

func InjectKey

func InjectKey[T any](v *T) any

func MapKeys

func MapKeys[T comparable, U any](m map[T]U) []T

func MapVals

func MapVals[T comparable, U any](m map[T]U) []U

func Must

func Must[T any](v T, err error) T

func Must0

func Must0(err error)

func Must2

func Must2[T1 any, T2 any](v1 T1, v2 T2, err error) (T1, T2)

func Must3

func Must3[T1 any, T2 any, T3 any](v1 T1, v2 T2, v3 T3, err error) (T1, T2, T3)

func Must4

func Must4[T1 any, T2 any, T3 any, T4 any](v1 T1, v2 T2, v3 T3, v4 T4, err error) (T1, T2, T3, T4)

func MustContext

func MustContext(ctx context.Context)

func MustDo

func MustDo(tasks ...Task)

func MustDoContext

func MustDoContext(ctx context.Context, tasks ...ContextTask)

func Ptr

func Ptr[T any](v T) *T

func Repeat

func Repeat[T any](count int, v T) []T

func SliceToMap

func SliceToMap[T any, U comparable](s []T, fn func(v T) U) map[U]T

Types

type ContextTask

type ContextTask = Executor11[context.Context, error]

type ContextTaskFunc

type ContextTaskFunc = Func11[context.Context, error]

type ErrorGroup

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

func NewErrorGroup

func NewErrorGroup() *ErrorGroup

func (*ErrorGroup) Add

func (eg *ErrorGroup) Add(err error)

func (*ErrorGroup) Unwrap

func (eg *ErrorGroup) Unwrap() error

type Errors

type Errors []error

func (Errors) Error

func (errs Errors) Error() string

type Executor01

type Executor01[O1 any] interface {
	Do() (o1 O1)
}

type Executor02

type Executor02[O1 any, O2 any] interface {
	Do() (o1 O1, o2 O2)
}

type Executor10

type Executor10[I1 any] interface {
	Do(i1 I1)
}

type Executor11

type Executor11[I1 any, O1 any] interface {
	Do(i1 I1) (o1 O1)
}

type Executor12

type Executor12[I1 any, O1 any, O2 any] interface {
	Do(i1 I1) (o1 O1, o2 O2)
}

type Executor21

type Executor21[I1 any, I2 any, O1 any] interface {
	Do(i1 I1, i2 I2) (o1 O1)
}

type Executor22

type Executor22[I1 any, I2 any, O1 any, O2 any] interface {
	Do(i1 I1, i2 I2) (o1 O1, o2 O2)
}

type Func01

type Func01[O1 any] func() (o1 O1)

func (Func01[O1]) Do

func (fn Func01[O1]) Do() O1

type Func02

type Func02[O1 any, O2 any] func() (o1 O1, o2 O2)

func (Func02[O1, O2]) Do

func (fn Func02[O1, O2]) Do() (O1, O2)

type Func10

type Func10[I1 any] func(i1 I1)

func (Func10[I1]) Do

func (fn Func10[I1]) Do(i1 I1)

type Func11

type Func11[I1 any, O1 any] func(i1 I1) (o1 O1)

func (Func11[I1, O1]) Do

func (fn Func11[I1, O1]) Do(i1 I1) O1

type Func12

type Func12[I1 any, O1 any, O2 any] func(i1 I1) (o1 O1, o2 O2)

func (Func12[I1, O1, O2]) Do

func (fn Func12[I1, O1, O2]) Do(i1 I1) (O1, O2)

type Func21

type Func21[I1 any, I2 any, O1 any] func(i1 I1, i2 I2) (o1 O1)

func (Func21[I1, I2, O1]) Do

func (fn Func21[I1, I2, O1]) Do(i1 I1, i2 I2) O1

type Func22

type Func22[I1 any, I2 any, O1 any, O2 any] func(i1 I1, i2 I2) (o1 O1, o2 O2)

func (Func22[I1, I2, O1, O2]) Do

func (fn Func22[I1, I2, O1, O2]) Do(i1 I1, i2 I2) (O1, O2)

type M

type M = map[string]interface{}

type Task

type Task = Executor01[error]

type TaskFunc

type TaskFunc = Func01[error]

Jump to

Keyboard shortcuts

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