gg

package module
v0.0.0-...-4e5cd15 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: 4

README

gg

Go Go Reference

A Go library to make code more elegant

Donation

Check https://guoyk.xyz/donation

Credits

Guo Y.K., MIT License

Documentation

Index

Constants

View Source
const (
	DebugWildcard  = "*"
	DebugSeparator = ":"
)

Variables

This section is empty.

Functions

func Debug

func Debug(v string) bool

Debug check weather a debug flag is enabled from environment variable $DEBUG

func Filter

func Filter[T any](s []T, fn func(T) bool) []T

Filter returns a new slice with element filtered

func Guard

func Guard(err *error)

Guard recover from panic and set err

func Keys

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

Keys extract keys of map

func Log

func Log(v ...interface{})

Log logs using the default logger

func Logf

func Logf(format string, v ...interface{})

Logf logs formatted using the default logger

func Map

func Map[T any, U any](s []T, fn func(T) U) []U

Map convert a slice to another by mapping each element

func Must

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

Must panic err if not nil, else return remaining values

func Must0

func Must0(err error)

Must0 panic err if not nil

func Must2

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

Must2 panic err if not nil, else return remaining values

func Must3

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

Must3 panic err if not nil, else return remaining values

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)

Must4 panic err if not nil, else return remaining values

func Must5

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

Must5 panic err if not nil, else return remaining values

func Must6

func Must6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, err error) (T1, T2, T3, T4, T5, T6)

Must6 panic err if not nil, else return remaining values

func Must7

func Must7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, err error) (T1, T2, T3, T4, T5, T6, T7)

Must7 panic err if not nil, else return remaining values

func MustContext

func MustContext(ctx context.Context)

MustContext panic ctx.Err() if not nil

func Ptr

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

Ptr create a pointer to a value

func Repeat

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

Repeat create a slice with a value repeated n times

func Set

func Set[T comparable](s []T) map[T]struct{}

Set convert a slice of comparables into a Set-like map

func Suppress

func Suppress(err *error, fns ...F11[error, bool]) error

Suppress set err to nil if one of fn returns true

func Values

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

Values extract values of map

Types

type D00

type D00 interface {
	Do()
}

D00 interface with a single method 0 with arguments and 0 returns

type D01

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

D01 interface with a single method 0 with arguments and 1 returns

type D02

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

D02 interface with a single method 0 with arguments and 2 returns

type D03

type D03[O1 any, O2 any, O3 any] interface {
	Do() (o1 O1, o2 O2, o3 O3)
}

D03 interface with a single method 0 with arguments and 3 returns

type D04

type D04[O1 any, O2 any, O3 any, O4 any] interface {
	Do() (o1 O1, o2 O2, o3 O3, o4 O4)
}

D04 interface with a single method 0 with arguments and 4 returns

type D10

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

D10 interface with a single method 1 with arguments and 0 returns

type D11

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

D11 interface with a single method 1 with arguments and 1 returns

type D12

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

D12 interface with a single method 1 with arguments and 2 returns

type D13

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

D13 interface with a single method 1 with arguments and 3 returns

type D14

type D14[I1 any, O1 any, O2 any, O3 any, O4 any] interface {
	Do(i1 I1) (o1 O1, o2 O2, o3 O3, o4 O4)
}

D14 interface with a single method 1 with arguments and 4 returns

type D20

type D20[I1 any, I2 any] interface {
	Do(i1 I1, i2 I2)
}

D20 interface with a single method 2 with arguments and 0 returns

type D21

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

D21 interface with a single method 2 with arguments and 1 returns

type D22

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

D22 interface with a single method 2 with arguments and 2 returns

type D23

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

D23 interface with a single method 2 with arguments and 3 returns

type D24

type D24[I1 any, I2 any, O1 any, O2 any, O3 any, O4 any] interface {
	Do(i1 I1, i2 I2) (o1 O1, o2 O2, o3 O3, o4 O4)
}

D24 interface with a single method 2 with arguments and 4 returns

type D30

type D30[I1 any, I2 any, I3 any] interface {
	Do(i1 I1, i2 I2, i3 I3)
}

D30 interface with a single method 3 with arguments and 0 returns

type D31

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

D31 interface with a single method 3 with arguments and 1 returns

type D32

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

D32 interface with a single method 3 with arguments and 2 returns

type D33

type D33[I1 any, I2 any, I3 any, O1 any, O2 any, O3 any] interface {
	Do(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2, o3 O3)
}

D33 interface with a single method 3 with arguments and 3 returns

type D34

type D34[I1 any, I2 any, I3 any, O1 any, O2 any, O3 any, O4 any] interface {
	Do(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2, o3 O3, o4 O4)
}

D34 interface with a single method 3 with arguments and 4 returns

type D40

type D40[I1 any, I2 any, I3 any, I4 any] interface {
	Do(i1 I1, i2 I2, i3 I3, i4 I4)
}

D40 interface with a single method 4 with arguments and 0 returns

type D41

type D41[I1 any, I2 any, I3 any, I4 any, O1 any] interface {
	Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1)
}

D41 interface with a single method 4 with arguments and 1 returns

type D42

type D42[I1 any, I2 any, I3 any, I4 any, O1 any, O2 any] interface {
	Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2)
}

D42 interface with a single method 4 with arguments and 2 returns

type D43

type D43[I1 any, I2 any, I3 any, I4 any, O1 any, O2 any, O3 any] interface {
	Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2, o3 O3)
}

D43 interface with a single method 4 with arguments and 3 returns

type D44

type D44[I1 any, I2 any, I3 any, I4 any, O1 any, O2 any, O3 any, O4 any] interface {
	Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2, o3 O3, o4 O4)
}

D44 interface with a single method 4 with arguments and 4 returns

type DebugSet

type DebugSet interface {
	Debug(v string) bool
}

func NewDebugSet

func NewDebugSet(debug string) DebugSet

NewDebugSet create a new DebugSet use comma ',' separate multiple items use '*' for wildcard, for example '*', 'echo:*,view:*'

type ErrorGroup

type ErrorGroup interface {
	Add(err error)
	Set(i int, err error)
	Unwrap() error
}

func NewErrorGroup

func NewErrorGroup() ErrorGroup

type Errors

type Errors []error

func (Errors) Error

func (errs Errors) Error() string

type F00

type F00 func()

F00 function with 0 arguments and 0 returns

func (F00) Do

func (f F00) Do()

type F01

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

F01 function with 0 arguments and 1 returns

func (F01[O1]) Do

func (f F01[O1]) Do() (o1 O1)

type F02

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

F02 function with 0 arguments and 2 returns

func (F02[O1, O2]) Do

func (f F02[O1, O2]) Do() (o1 O1, o2 O2)

type F03

type F03[O1 any, O2 any, O3 any] func() (o1 O1, o2 O2, o3 O3)

F03 function with 0 arguments and 3 returns

func (F03[O1, O2, O3]) Do

func (f F03[O1, O2, O3]) Do() (o1 O1, o2 O2, o3 O3)

type F04

type F04[O1 any, O2 any, O3 any, O4 any] func() (o1 O1, o2 O2, o3 O3, o4 O4)

F04 function with 0 arguments and 4 returns

func (F04[O1, O2, O3, O4]) Do

func (f F04[O1, O2, O3, O4]) Do() (o1 O1, o2 O2, o3 O3, o4 O4)

type F10

type F10[I1 any] func(i1 I1)

F10 function with 1 arguments and 0 returns

func (F10[I1]) Do

func (f F10[I1]) Do(i1 I1)

type F11

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

F11 function with 1 arguments and 1 returns

func Eq

func Eq[T comparable](v T) F11[T, bool]

Eq returns a func that returns true if incoming value is same

func Neq

func Neq[T comparable](v T) F11[T, bool]

Neq returns a func that returns true if incoming value is not same

func (F11[I1, O1]) Do

func (f F11[I1, O1]) Do(i1 I1) (o1 O1)

type F12

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

F12 function with 1 arguments and 2 returns

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

func (f F12[I1, O1, O2]) Do(i1 I1) (o1 O1, o2 O2)

type F13

type F13[I1 any, O1 any, O2 any, O3 any] func(i1 I1) (o1 O1, o2 O2, o3 O3)

F13 function with 1 arguments and 3 returns

func (F13[I1, O1, O2, O3]) Do

func (f F13[I1, O1, O2, O3]) Do(i1 I1) (o1 O1, o2 O2, o3 O3)

type F14

type F14[I1 any, O1 any, O2 any, O3 any, O4 any] func(i1 I1) (o1 O1, o2 O2, o3 O3, o4 O4)

F14 function with 1 arguments and 4 returns

func (F14[I1, O1, O2, O3, O4]) Do

func (f F14[I1, O1, O2, O3, O4]) Do(i1 I1) (o1 O1, o2 O2, o3 O3, o4 O4)

type F20

type F20[I1 any, I2 any] func(i1 I1, i2 I2)

F20 function with 2 arguments and 0 returns

func (F20[I1, I2]) Do

func (f F20[I1, I2]) Do(i1 I1, i2 I2)

type F21

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

F21 function with 2 arguments and 1 returns

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

func (f F21[I1, I2, O1]) Do(i1 I1, i2 I2) (o1 O1)

type F22

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

F22 function with 2 arguments and 2 returns

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

func (f F22[I1, I2, O1, O2]) Do(i1 I1, i2 I2) (o1 O1, o2 O2)

type F23

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

F23 function with 2 arguments and 3 returns

func (F23[I1, I2, O1, O2, O3]) Do

func (f F23[I1, I2, O1, O2, O3]) Do(i1 I1, i2 I2) (o1 O1, o2 O2, o3 O3)

type F24

type F24[I1 any, I2 any, O1 any, O2 any, O3 any, O4 any] func(i1 I1, i2 I2) (o1 O1, o2 O2, o3 O3, o4 O4)

F24 function with 2 arguments and 4 returns

func (F24[I1, I2, O1, O2, O3, O4]) Do

func (f F24[I1, I2, O1, O2, O3, O4]) Do(i1 I1, i2 I2) (o1 O1, o2 O2, o3 O3, o4 O4)

type F30

type F30[I1 any, I2 any, I3 any] func(i1 I1, i2 I2, i3 I3)

F30 function with 3 arguments and 0 returns

func (F30[I1, I2, I3]) Do

func (f F30[I1, I2, I3]) Do(i1 I1, i2 I2, i3 I3)

type F31

type F31[I1 any, I2 any, I3 any, O1 any] func(i1 I1, i2 I2, i3 I3) (o1 O1)

F31 function with 3 arguments and 1 returns

func (F31[I1, I2, I3, O1]) Do

func (f F31[I1, I2, I3, O1]) Do(i1 I1, i2 I2, i3 I3) (o1 O1)

type F32

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

F32 function with 3 arguments and 2 returns

func (F32[I1, I2, I3, O1, O2]) Do

func (f F32[I1, I2, I3, O1, O2]) Do(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2)

type F33

type F33[I1 any, I2 any, I3 any, O1 any, O2 any, O3 any] func(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2, o3 O3)

F33 function with 3 arguments and 3 returns

func (F33[I1, I2, I3, O1, O2, O3]) Do

func (f F33[I1, I2, I3, O1, O2, O3]) Do(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2, o3 O3)

type F34

type F34[I1 any, I2 any, I3 any, O1 any, O2 any, O3 any, O4 any] func(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2, o3 O3, o4 O4)

F34 function with 3 arguments and 4 returns

func (F34[I1, I2, I3, O1, O2, O3, O4]) Do

func (f F34[I1, I2, I3, O1, O2, O3, O4]) Do(i1 I1, i2 I2, i3 I3) (o1 O1, o2 O2, o3 O3, o4 O4)

type F40

type F40[I1 any, I2 any, I3 any, I4 any] func(i1 I1, i2 I2, i3 I3, i4 I4)

F40 function with 4 arguments and 0 returns

func (F40[I1, I2, I3, I4]) Do

func (f F40[I1, I2, I3, I4]) Do(i1 I1, i2 I2, i3 I3, i4 I4)

type F41

type F41[I1 any, I2 any, I3 any, I4 any, O1 any] func(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1)

F41 function with 4 arguments and 1 returns

func (F41[I1, I2, I3, I4, O1]) Do

func (f F41[I1, I2, I3, I4, O1]) Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1)

type F42

type F42[I1 any, I2 any, I3 any, I4 any, O1 any, O2 any] func(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2)

F42 function with 4 arguments and 2 returns

func (F42[I1, I2, I3, I4, O1, O2]) Do

func (f F42[I1, I2, I3, I4, O1, O2]) Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2)

type F43

type F43[I1 any, I2 any, I3 any, I4 any, O1 any, O2 any, O3 any] func(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2, o3 O3)

F43 function with 4 arguments and 3 returns

func (F43[I1, I2, I3, I4, O1, O2, O3]) Do

func (f F43[I1, I2, I3, I4, O1, O2, O3]) Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2, o3 O3)

type F44

type F44[I1 any, I2 any, I3 any, I4 any, O1 any, O2 any, O3 any, O4 any] func(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2, o3 O3, o4 O4)

F44 function with 4 arguments and 4 returns

func (F44[I1, I2, I3, I4, O1, O2, O3, O4]) Do

func (f F44[I1, I2, I3, I4, O1, O2, O3, O4]) Do(i1 I1, i2 I2, i3 I3, i4 I4) (o1 O1, o2 O2, o3 O3, o4 O4)

type Logger

type Logger interface {
	// Log inserts a log entry.  Arguments may be handled in the manner
	// of fmt.Print, but the underlying logger may also decide to handle
	// them differently.
	Log(v ...interface{})
	// Logf insets a log entry.  Arguments are handled in the manner of
	// fmt.Printf.
	Logf(format string, v ...interface{})
}

Logger is a generic logging interface

var (
	// DefaultLogger The global default logger
	DefaultLogger Logger = &stdLogger{}
)

type M

type M = map[string]interface{}

type T2

type T2[I1 any, I2 any] struct {
	A I1
	B I2
}

T2 tuple with 2 fields

type T3

type T3[I1 any, I2 any, I3 any] struct {
	A I1
	B I2
	C I3
}

T3 tuple with 3 fields

type T4

type T4[I1 any, I2 any, I3 any, I4 any] struct {
	A I1
	B I2
	C I3
	D I4
}

T4 tuple with 4 fields

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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