attrutils

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyString      = errors.New("empty string")
	ErrConvertingString = errors.New("error converting string to number")
)

Functions

func AddStructField

func AddStructField(typIndirected reflect.Type, name string, field *reflect.StructField)

func AddStructMethod

func AddStructMethod(typIndirected reflect.Type, name string, method reflect.Method)

func AttrFromMap

func AttrFromMap[T any](attrMap map[string]any, attrName string) (T, bool, error)

func BuilderMethod

func BuilderMethod[BUILDER any](bld BUILDER, methodName string, args ...any) (BUILDER, []any, error)

func CastToNumber

func CastToNumber[T any](v any) (T, error)

CastToNumber converts a value of any type (int, float, string) to a number of type T. It returns the converted value and an error if the conversion fails.

func GetStructField

func GetStructField(typIndirected reflect.Type, name string) (*reflect.StructField, bool)

func GetStructMethod

func GetStructMethod(typIndirected reflect.Type, name string) (reflect.Method, bool)

func InterfaceList

func InterfaceList[T any](list []T) []any

InterfaceList converts a slice of []T to []any.

Types

type Builder

type Builder[T any] struct {
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder[T any](t T) *Builder[T]

func (*Builder[T]) Call

func (b *Builder[T]) Call(methodName string, args ...any) (T, []any, error)

func (*Builder[T]) Chain

func (b *Builder[T]) Chain(methodName string, args ...any) *Builder[T]

func (*Builder[T]) Error

func (b *Builder[T]) Error() error

func (*Builder[T]) Exec

func (b *Builder[T]) Exec(fn func(bld T) (T, error)) (T, error)

func (*Builder[T]) HasMethod

func (b *Builder[T]) HasMethod(methodName string) bool

func (*Builder[T]) Orig

func (b *Builder[T]) Orig() T

func (*Builder[T]) Ref

func (b *Builder[T]) Ref() T

type ObjectBuilder

type ObjectBuilder[T any] interface {
	CallBuilderMethod(methodName string, args ...any) (T, []any, error)
}

Jump to

Keyboard shortcuts

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