Documentation ¶
Index ¶
- Variables
- func MapDelete[K comparable](m reflect.Value, k K) error
- func MapGet[V any, K comparable](m reflect.Value, k K) (V, error)
- func MapKeys(m reflect.Value) ([]reflect.Value, error)
- func MapLen(m reflect.Value) (int, error)
- func MapSet[K comparable, V any](m reflect.Value, k K, v V) error
- func SliceAppend[T any](s reflect.Value, v T) ([]T, error)
- func SliceAs[T any](s reflect.Value) ([]T, error)
- func SliceGet[T any](s reflect.Value, i int) (T, error)
- func SliceGetAll(s reflect.Value) ([]reflect.Value, error)
- func SliceLen(s reflect.Value) (int, error)
- func SliceSet[T any](s reflect.Value, i int, v T) error
- func StructGetField[T any](v reflect.Value, name string, caseSensitive bool) (T, error)
- func StructListFields(v reflect.Value, listUnexportedFields bool, customTag string) ([]string, error)
- func StructSetField[T any](v reflect.Value, name string, value T, caseSensitive bool) error
- func StructToMap(v reflect.Value, parseJSONTag bool, ...) (map[string]any, error)
- func StructToMapEx(v reflect.Value, customTag string, ...) (map[string]any, error)
- func ValueAs[T any](v reflect.Value) (T, error)
- type MapEntry
- type Tag
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTypeInvalid = errors.New("ErrTypeInvalid") ErrTypeUnmatched = errors.New("ErrTypeUnmatched") ErrNotFound = errors.New("ErrNotFound") ErrValueUnaddressable = errors.New("ErrValueUnaddressable") ErrValueUnsettable = errors.New("ErrValueUnsettable") ErrIndexOutOfRange = errors.New("ErrIndexOutOfRange") )
Functions ¶
func MapDelete ¶
func MapDelete[K comparable](m reflect.Value, k K) error
MapDelete delete the given key from a map
func MapGet ¶
func MapGet[V any, K comparable](m reflect.Value, k K) (V, error)
MapGet get value from a map by key
func MapSet ¶
func MapSet[K comparable, V any](m reflect.Value, k K, v V) error
MapSet set value for a key of a map
func SliceAppend ¶
SliceAppend appends the given value to a slice
func SliceGetAll ¶
SliceGetAll get all elements of a slice
func StructGetField ¶
StructGetField get struct field value by field name as T type Input should be a struct, a ptr to a struct, or an interface containing a struct
func StructListFields ¶
func StructSetField ¶
StructSetField set struct field value by field name as T type
func StructToMap ¶
func StructToMap( v reflect.Value, parseJSONTag bool, keyFunc func(name string, isExported bool) string, ) (map[string]any, error)
StructToMap convert a struct to a map Pass the keyFunc as nil to default to use field name and ignore unexported fields.
Types ¶
type Tag ¶
type Tag struct { Name string FieldName string Ignored bool // when name is "-" Attrs map[string]string }
func ParseTag ¶
func ParseTag(field *reflect.StructField, tagName, delim string) (*Tag, error)
ParseTag parse tag for the given struct field
func ParseTagOf ¶
ParseTagOf parse tag for the struct and field name
func ParseTagsOf ¶
ParseTagsOf parse tags of all struct fields
Click to show internal directories.
Click to hide internal directories.