Documentation ¶
Index ¶
- func Map(attrs ...Attr) map[string]any
- type Attr
- func Complex[T ComplexRestriction](key string, value T) Attr
- func Float[T FloatRestriction](key string, value T) Attr
- func Int[T IntRestriction](key string, value T) Attr
- func New[T any](key string, value T) Attr
- func Ptr[T any](key string, value *T) Attr
- func String[T CharRestriction](key string, value T) Attr
- func Uint[T UintRestriction](key string, value T) Attr
- type Attrs
- type BoolRestriction
- type CharRestriction
- type ComplexRestriction
- type FloatRestriction
- type IntRestriction
- type NumberRestriction
- type TextRestriction
- type TimeRestriction
- type UintRestriction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Attr ¶
type Attr interface { // Key returns the string key of the attribute Attr Key() string // Value returns the (any) value of the attribute Attr Value() any // WithKey returns a copy of this Attr, with key `key` WithKey(key string) Attr // WithValue returns a copy of this Attr, with value `value` // // It must be the same type of the original Attr, otherwise returns // nil WithValue(value any) Attr }
Attr interface describes the behavior that a serializable attribute should have.
Besides retrieving its key and value, it also permits creating a copy of the original Attr with a different key or a different value
func Complex ¶
func Complex[T ComplexRestriction](key string, value T) Attr
Complex is a generic function to create Attr attributes based on complex values. It converts the values to complex128
func Float ¶
func Float[T FloatRestriction](key string, value T) Attr
Float is a generic function to create Attr attributes based on float values. It converts the values to float64
func Int ¶
func Int[T IntRestriction](key string, value T) Attr
Int is a generic function to create Attr attributes based on int values. It converts the values to int64
func New ¶
New is a generic function to create an Attr
Using a generic approach allows the Attr.WithValue method to be scoped with certain constraints for specific applications
func Ptr ¶
Ptr is a generic function to create an Attr from a pointer value
Using a generic approach allows the Attr.WithValue method to be scoped with certain constraints for specific applications
func String ¶
func String[T CharRestriction](key string, value T) Attr
String is a generic function to create Attr attributes based on string values. It converts the values to string
func Uint ¶
func Uint[T UintRestriction](key string, value T) Attr
Uint is a generic function to create Attr attributes based on uint values. It converts the values to uint64
type Attrs ¶
type Attrs []Attr
func (Attrs) MarshalJSON ¶
MarshalJSON encodes the attributes as a JSON object (key-value pairs)
func (Attrs) MarshalText ¶
type BoolRestriction ¶
type BoolRestriction interface { ~bool }
BoolRestriction is a constraint that only accepts booleans
type CharRestriction ¶
CharRestriction is a constraint that only accepts stringifiable tokens
type ComplexRestriction ¶
type ComplexRestriction interface { ~complex64 | ~complex128 }
ComplexRestriction is a constraint that only accepts complex values
type FloatRestriction ¶
FloatRestriction is a constraint that only accepts float values
type IntRestriction ¶
IntRestriction is a constraint that only accepts int values
type NumberRestriction ¶
type NumberRestriction interface { IntRestriction | UintRestriction | FloatRestriction | ComplexRestriction }
NumberRestriction is a constraint that only accepts number values, as a combination of other constraints
type TextRestriction ¶
type TextRestriction interface { CharRestriction | BoolRestriction | TimeRestriction }
TextRestriction is a constraint that only accepts text values, as a combination of other constraints
type TimeRestriction ¶
TimeRestriction is a constraint that only accepts time.Time values