Documentation
¶
Overview ¶
Package utilx provides additional utility functions.
Index ¶
- func And[T comparable](a, b T) T
- func Empty[T comparable](value T) bool
- func Equal[T comparable](a, b T) bool
- func IfElse[T any](condition bool, v1, v2 T) T
- func IsNil(value any) bool
- func NotEmpty[T comparable](value T) bool
- func NotEqual[T comparable](a, b T) bool
- func NotNil(value any) bool
- func Or[T comparable](a, b T) T
- func SetDefaults(variable interface{})
- type FieldData
- type Filler
- type FillerFunc
- type TypeHash
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Empty ¶
func Empty[T comparable](value T) bool
Empty returns true of the given value is equal to the default empty value.
func Equal ¶ added in v0.7.6
func Equal[T comparable](a, b T) bool
Equal returns true of the given values are equal.
func NotEmpty ¶
func NotEmpty[T comparable](value T) bool
NotEmpty returns true of the given value is not equal to the default empty value.
func NotEqual ¶ added in v0.7.10
func NotEqual[T comparable](a, b T) bool
NotEqual returns true of the given values are not equal.
func SetDefaults ¶
func SetDefaults(variable interface{})
SetDefaults sets the default values for the fields of the given struct.
Usage
type ExampleBasic struct {
Foo bool `default:"true"`
Bar string `default:"33"`
Qux int8
Dur time.Duration `default:"2m3s"`
}
foo := &ExampleBasic{}
SetDefaults(foo)
Types ¶
type FieldData ¶
type FieldData struct {
Field reflect.StructField
Value reflect.Value
TagValue string
Parent *FieldData
}
FieldData contains the information of a field of a struct.
type Filler ¶
type Filler struct {
FuncByName map[string]FillerFunc
FuncByType map[TypeHash]FillerFunc
FuncByKind map[reflect.Kind]FillerFunc
Tag string
}
Filler contains all the functions to fill any struct field with any type allowing to define function by Kind, Type of field name.
func (*Filler) Fill ¶
func (f *Filler) Fill(variable interface{})
Fill apply all the functions contained on Filler, setting all the possible values.
func (*Filler) GetFieldsFromValue ¶
GetFieldsFromValue returns all the fields of a struct.
func (*Filler) SetDefaultValue ¶
SetDefaultValue sets the default value for a field.
func (*Filler) SetDefaultValues ¶
SetDefaultValues sets the default values for all the fields.
type FillerFunc ¶
type FillerFunc func(field *FieldData)
FillerFunc is a function that fills a field with a specific.