Documentation
¶
Overview ¶
Package utilx provides additional utility functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func And ¶ added in v0.1.9
func And[T comparable](a, b T) T
And works similar to "&&" in other languages.
func Empty ¶
func Empty[T comparable](value T) bool
Empty returns true of the given value is equal to the default empty value.
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 SetDefaults ¶ added in v0.1.20
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 ¶ added in v0.1.20
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 ¶ added in v0.1.20
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 ¶ added in v0.1.20
func (f *Filler) Fill(variable interface{})
Fill apply all the functions contained on Filler, setting all the possible values.
func (*Filler) GetFieldsFromValue ¶ added in v0.1.20
GetFieldsFromValue returns all the fields of a struct
func (*Filler) SetDefaultValue ¶ added in v0.1.20
SetDefaultValue sets the default value for a field
func (*Filler) SetDefaultValues ¶ added in v0.1.20
SetDefaultValues sets the default values for all the fields
type FillerFunc ¶ added in v0.1.20
type FillerFunc func(field *FieldData)
FillerFunc is a function that fills a field with a specific