utilx

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 6 Imported by: 16

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 Equal added in v0.2.0

func Equal[T comparable](a, b T) bool

Equal returns true of the given values are equal.

func IfElse

func IfElse[T any](condition bool, v1, v2 T) T

IfElse works similar to "?:", "if-else" in other languages.

func IsNil added in v0.2.0

func IsNil(value any) bool

IsNil returns true of the given value is nil.

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.2.0

func NotEqual[T comparable](a, b T) bool

NotEqual returns true of the given values are not equal.

func NotNil added in v0.2.0

func NotNil(value any) bool

NotNil returns true of the given value is not nil.

func Or

func Or[T comparable](a, b T) T

Or works similar to "||" in other languages.

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

func (f *Filler) GetFieldsFromValue(valueObject reflect.Value, parent *FieldData) []*FieldData

GetFieldsFromValue returns all the fields of a struct.

func (*Filler) SetDefaultValue added in v0.1.20

func (f *Filler) SetDefaultValue(field *FieldData)

SetDefaultValue sets the default value for a field.

func (*Filler) SetDefaultValues added in v0.1.20

func (f *Filler) SetDefaultValues(fields []*FieldData)

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.

type TypeHash added in v0.1.20

type TypeHash string

TypeHash is a string representing a reflect.Type following the next pattern: <package.name>.<type.name>.

func GetTypeHash added in v0.1.20

func GetTypeHash(t reflect.Type) TypeHash

GetTypeHash returns the TypeHash for a given reflect.Type.

Jump to

Keyboard shortcuts

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