Documentation ¶
Index ¶
- Variables
- func Clone[K comparable, V any, M ~map[K]V](m M) M
- func ConcatSlices[T any](slices ...[]T) []T
- func ExtractMultiTypeTypes(mtType reflect.Type) ([]reflect.Type, error)
- func Filter[T any](elements []T, filterFn func(T) bool) []T
- func Find[T any](elements []T, findFn func(T) bool) (T, bool)
- func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
- func GetType[T any]() reflect.Type
- func IndexOf[T any](elements []T, findFn func(T) bool) int
- func IsMultiType(t reflect.Type) bool
- func Keys[K comparable, V any, M ~map[K]V](m M) []K
- func LastIndexOf[T any](elements []T, findFn func(T) bool) int
- func Map[T, R any](elements []T, mapFn func(T) R) []R
- func Ptr[T any](value T) *T
- func StructKeys(structType reflect.Type, tag string) map[string]reflect.StructField
- func Values[K comparable, V any, M ~map[K]V](m M) []V
- type Entry
- type InMemoryLogger
- type LogCounters
- type LogLevel
- type Logger
- type MultiType
- type Nil
- type Set
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidUseOfMultiType = errors.New("invalid use of MultiType")
var NilType = GetType[Nil]()
NilType represent the type of Nil.
Functions ¶
func Clone ¶
func Clone[K comparable, V any, M ~map[K]V](m M) M
func ConcatSlices ¶
func ConcatSlices[T any](slices ...[]T) []T
func ExtractMultiTypeTypes ¶ added in v1.2.0
func FromEntries ¶
func FromEntries[K comparable, V any](entries []Entry[K, V]) map[K]V
func IsMultiType ¶ added in v1.2.0
func Keys ¶
func Keys[K comparable, V any, M ~map[K]V](m M) []K
func LastIndexOf ¶
func StructKeys ¶ added in v1.2.0
StructKeys returns a map of "key" -> "field" for all the fields in the struct. Key is the field tag if exists or the field name otherwise. Field is the reflect.StructField of the field.
Unexported fields or fields with tag value of "-" are ignored.
StructKeys will recursively traverse all the embedded structs and return their fields as well.
func Values ¶
func Values[K comparable, V any, M ~map[K]V](m M) []V
Types ¶
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V }
func Entries ¶
func Entries[K comparable, V any, M ~map[K]V](m M) []Entry[K, V]
type InMemoryLogger ¶
func NewInMemoryLogger ¶
func NewInMemoryLogger() InMemoryLogger
func NewInMemoryLoggerWithLevel ¶
func NewInMemoryLoggerWithLevel(level LogLevel) InMemoryLogger
type LogCounters ¶
type LogLevel ¶
type LogLevel int
func (LogLevel) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (*LogLevel) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
type Logger ¶
type Logger interface { Log(LogLevel, any) Logf(LogLevel, string, ...any) LogIfNotNil(LogLevel, any) bool LogIfNotNilf(LogLevel, any, string, ...any) bool Info(any) Infof(string, ...any) Warn(any) Warnf(string, ...any) Error(any) Errorf(string, ...any) ErrorIfNotNil(any) bool ErrorIfNotNilf(any, string, ...any) bool WarnIfNotNil(any) bool WarnIfNotNilf(any, string, ...any) bool Counters() LogCounters Warnings() int Errors() int MustHaveNoWarnings() error MustHaveNoErrors() error MustHaveNoWarningsf(string, ...any) error MustHaveNoErrorsf(string, ...any) error AppendCounters(LogCounters) // NewCounter creates a cloned logger with the same output and log level but with new counters NewCounter() Logger WithLevel(level LogLevel) }
Logger act as a regular logger that counts logged errors and warnings.
type MultiType ¶ added in v1.2.0
type MultiType[T any] struct { Values T }
func (*MultiType[T]) MarshalJSON ¶ added in v1.2.0
func (*MultiType[T]) MultiTypeTypes ¶ added in v1.2.0
func (*MultiType[T]) UnmarshalJSON ¶ added in v1.2.0
type Nil ¶ added in v1.2.0
type Nil *uintptr
Nil represents an empty type. You can use it with the HandlerFunc generic parameters to declare no Request with no request body, no path or query params, or responses with no response body.
type Set ¶
type Set[T comparable] map[T]bool
Set keeps a collection of unique items with efficient access for addition, removal and check existence of elements.
func NewSet ¶
func NewSet[T comparable](elements ...T) Set[T]
NewSet creates a new Set and populate it with the provided elements. duplicate elements will be saved once
func (Set[T]) Add ¶
Add an element to the set. returns true if the element is a new element in the set and false if the element was already part of the set.