Documentation ¶
Index ¶
- Variables
- func AnySlice[R any](src any, tags ...string) []R
- func AnySliceContext[R any](ctx context.Context, src any, tags ...string) []R
- func Bool(v any) bool
- func Cast[R any, T any](v T, tags ...string) R
- func CastContext[R any, T any](ctx context.Context, v T, tags ...string) R
- func CastRecursive[R any, T any](v T, tags ...string) R
- func CastRecursiveContext[R any, T any](ctx context.Context, v T, tags ...string) R
- func Float(v any) float64
- func Float32(v any) float32
- func Float64(v any) float64
- func IfThen[T any](cond bool, a, b T) T
- func IfThenExec[T any](cond bool, a func() T, b func() T) T
- func Int(v any) int
- func Int16(v any) int16
- func Int32(v any) int32
- func Int64(v any) int64
- func Int8(v any) int8
- func IsEmpty[T any](v T) bool
- func IsEmptyByReflection(v reflect.Value) bool
- func IsMap(v any) bool
- func IsNumeric10Str(s string) bool
- func IsNumericOnlyStr(s string) bool
- func IsNumericStr(s string) bool
- func IsSlice(v any) bool
- func IsStr(v any) bool
- func IsStrContainsOf(s, subset string) bool
- func IsStruct(v any) bool
- func Len[T any](val T) int
- func Map[K comparable, V any](src any, tags ...string) map[K]V
- func MapContext[K comparable, V any](ctx context.Context, src any, tags ...string) map[K]V
- func MapRecursive[K comparable, V any](src any, tags ...string) map[K]V
- func MapRecursiveContext[K comparable, V any](ctx context.Context, src any, tags ...string) map[K]V
- func Number[R Numeric](v any) R
- func Or[T any](a, b T, v ...T) T
- func ParseTime(tm string) (t time.Time, err error)
- func PtrAsValue[T any](v *T, def T) T
- func ReflectStr(v reflect.Value) string
- func ReflectStructAllFieldNames(t reflect.Type, tags ...string) map[string][]string
- func ReflectStructAllFieldNamesContext(ctx context.Context, t reflect.Type, tags ...string) map[string][]string
- func ReflectStructFieldNames(t reflect.Type, tag string) []string
- func ReflectStructFieldTagsUnsorted(t reflect.Type, tag string) ([]string, []string)
- func ReflectStructFieldValue(st reflect.Value, names ...string) (any, error)
- func ReflectStructFields(t reflect.Type) []reflect.StructField
- func ReflectToBool(v reflect.Value) bool
- func ReflectToFloat64(v reflect.Value) float64
- func ReflectToInt64(v reflect.Value) int64
- func ReflectToString(v reflect.Value) stringdeprecated
- func ReflectToType(v reflect.Value, t reflect.Type, tags ...string) any
- func ReflectToTypeContext(ctx context.Context, v reflect.Value, t reflect.Type, tags ...string) any
- func ReflectTryToType(v reflect.Value, t reflect.Type, recursive bool, tags ...string) (any, error)
- func ReflectTryToTypeContext(ctx context.Context, srcVal reflect.Value, t reflect.Type, recursive bool, ...) (any, error)
- func SetStructFieldValue(ctx context.Context, st any, name string, value any) (err error)
- func Slice[R any, S any](src []S, tags ...string) []R
- func SliceContext[R any, S any](ctx context.Context, src []S, tags ...string) []R
- func Str(v any) string
- func Struct[R any](src any, tags ...string) (R, error)
- func StructAllFieldNames(st any, tags ...string) map[string][]string
- func StructAllFieldNamesContext(ctx context.Context, st any, tags ...string) map[string][]string
- func StructContext[R any](ctx context.Context, src any, tags ...string) (R, error)
- func StructFieldNames(st any, tag string) []string
- func StructFieldTags(st any, tag string) map[string]string
- func StructFieldTagsUnsorted(st any, tag string) ([]string, []string)
- func StructFieldValue(st any, names ...string) (any, error)
- func StructWalk(ctx context.Context, v any, walker structWalkerFunc, options ...WalkOption) error
- func To(v, to any, tags ...string) any
- func ToBool(v any) booldeprecated
- func ToFloat(v any) float64deprecated
- func ToFloat32(v any) float32deprecated
- func ToFloat64(v any) float64deprecated
- func ToFloat64Slice(v any) []float64deprecated
- func ToInt(v any) intdeprecated
- func ToInt16(v any) int16deprecated
- func ToInt32(v any) int32deprecated
- func ToInt64(v any) int64deprecated
- func ToIntSlice(v any) []intdeprecated
- func ToInterfaceSlice(v any) []anydeprecated
- func ToMap(dst, src any, recursive bool, tags ...string) error
- func ToMapContext(ctx context.Context, dst, src any, recursive bool, tags ...string) error
- func ToMapFrom(src any, recursive bool, tags ...string) (map[any]any, error)
- func ToSiMap(src any, recursive bool, tags ...string) (map[string]any, error)deprecated
- func ToSlice(dst, src any, tags ...string) errordeprecated
- func ToString(v any) stringdeprecated
- func ToStringMap(src any, recursive bool, tags ...string) (map[string]string, error)deprecated
- func ToStringSlice(v any) []stringdeprecated
- func ToStruct(dst, src any, tags ...string) errordeprecated
- func ToType(v any, t reflect.Type, tags ...string) any
- func ToUint(v any) uintdeprecated
- func ToUint16(v any) uint16deprecated
- func ToUint32(v any) uint32deprecated
- func ToUint64(v any) uint64deprecated
- func ToUint64ByReflect(v reflect.Value) uint64
- func TryAnySlice[R any](src any, tags ...string) (res []R, err error)
- func TryAnySliceContext[R any](ctx context.Context, src any, tags ...string) ([]R, error)
- func TryCast[R any, T any](v T, tags ...string) (R, error)
- func TryCastContext[R any, T any](ctx context.Context, v T, tags ...string) (R, error)
- func TryCastRecursive[R any, T any](v T, tags ...string) (R, error)
- func TryCastRecursiveContext[R any, T any](ctx context.Context, v T, tags ...string) (R, error)
- func TryCastValue[R any, T any](v T, recursive bool, tags ...string) (R, error)
- func TryCastValueContext[R any, T any](ctx context.Context, v T, recursive bool, tags ...string) (R, error)
- func TryCopyStruct(dst, src any, tags ...string) (err error)
- func TryCopyStructContext(ctx context.Context, dst, src any, tags ...string) (err error)
- func TryMap[K comparable, V any](src any, tags ...string) (map[K]V, error)
- func TryMapContext[K comparable, V any](ctx context.Context, src any, tags ...string) (map[K]V, error)
- func TryMapCopy[K comparable, V any](dst map[K]V, src any, recursive bool, tags ...string) error
- func TryMapCopyContext[K comparable, V any](ctx context.Context, dst map[K]V, src any, recursive bool, tags ...string) error
- func TryMapFrom[K comparable, V any](src any, recursive bool, tags ...string) (map[K]V, error)
- func TryMapFromContext[K comparable, V any](ctx context.Context, src any, recursive bool, tags ...string) (map[K]V, error)
- func TryMapRecursive[K comparable, V any](src any, tags ...string) (map[K]V, error)
- func TryMapRecursiveContext[K comparable, V any](ctx context.Context, src any, tags ...string) (map[K]V, error)
- func TryNumber[R Numeric](v any) (R, error)
- func TryReflectStr(v reflect.Value) (string, error)
- func TryReflectToString(v reflect.Value) (string, error)deprecated
- func TrySlice[R any, S any](src []S, tags ...string) (res []R, err error)
- func TrySliceContext[R any, S any](ctx context.Context, src []S, tags ...string) (res []R, err error)
- func TryStr(v any) (string, error)
- func TryTo(v, to any, tags ...string) (any, error)
- func TryToAnySliceContext(ctx context.Context, dst, src any, tags ...string) error
- func TryToContext(ctx context.Context, v, to any, tags ...string) (any, error)
- func TryToString(v any) (string, error)deprecated
- func TryToType(v any, t reflect.Type, tags ...string) (any, error)
- func TryToTypeContext(ctx context.Context, v any, t reflect.Type, tags ...string) (any, error)
- func Uint(v any) uint
- func Uint16(v any) uint16
- func Uint32(v any) uint32
- func Uint64(v any) uint64
- func Uint8(v any) uint8
- type CastSetter
- type Numeric
- type StructWalkField
- type StructWalkObject
- type StructWalkOptions
- type WalkOption
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidParams = errors.New("invalid params") ErrUnsupportedType = errors.New("unsupported destination type") ErrUnsupportedSourceType = errors.New("unsupported source type") ErrUnsettableValue = errors.New("can't set value") ErrUnsupportedNumericType = errors.New("unsupported numeric type") ErrStructFieldNameUndefined = errors.New("struct field name undefined") ErrStructFieldValueCantBeChanged = errors.New("struct field value cant be changed") )
Error list...
var ( ErrWalkSkip = errors.New("skip field walk") ErrWalkStop = errors.New("stop field walk") )
Functions ¶
func AnySlice ¶ added in v2.6.0
AnySlice converts any input slice into destination type slice as return value
func AnySliceContext ¶ added in v2.6.0
AnySliceContext converts any input slice into destination type slice as return value
func CastContext ¶ added in v2.2.3
CastContext source type into the target type
func CastRecursive ¶
CastRecursive source type into the target type
func CastRecursiveContext ¶ added in v2.2.3
CastRecursiveContext source type into the target type
func IfThenExec ¶ added in v2.9.0
IfThenExec returns a() if cond is true, else b()
func IsNumeric10Str ¶ added in v2.6.0
IsNumeric10Str returns true if input string is a numeric in base 10
func IsNumericOnlyStr ¶ added in v2.6.0
IsNumericOnlyStr returns true if input string is a numeric only
func IsNumericStr ¶ added in v2.6.0
IsNumeric returns true if input is a numeric
func IsStrContainsOf ¶ added in v2.6.0
IsStrContainsOf returns true if input string contains only chars from subset
func Map ¶
func Map[K comparable, V any](src any, tags ...string) map[K]V
Map creates map from source or returns nil
func MapContext ¶ added in v2.3.0
MapContext creates map from source or returns nil
func MapRecursive ¶
func MapRecursive[K comparable, V any](src any, tags ...string) map[K]V
MapRecursive creates map from source or returns nil
func MapRecursiveContext ¶ added in v2.3.0
MapRecursiveContext creates map from source or returns nil
func PtrAsValue ¶ added in v2.8.1
func PtrAsValue[T any](v *T, def T) T
PtrAsValue returns the value of `v` if `v` is not `nil`, else def
func ReflectStr ¶
ReflectStr converts reflection value to string
func ReflectStructAllFieldNames ¶ added in v2.7.2
ReflectStructAllFieldNames returns the field names from the structure including names from tags
func ReflectStructAllFieldNamesContext ¶ added in v2.7.2
func ReflectStructAllFieldNamesContext(ctx context.Context, t reflect.Type, tags ...string) map[string][]string
ReflectStructAllFieldNamesContext returns the field names from the structure including names from tags
func ReflectStructFieldNames ¶ added in v2.7.0
ReflectStructFieldNames returns the field names from the structure
func ReflectStructFieldTagsUnsorted ¶ added in v2.7.0
ReflectStructFieldTagsUnsorted returns field names and tag targets separately
func ReflectStructFieldValue ¶ added in v2.2.1
ReflectStructFieldValue returns the value of the struct field
func ReflectStructFields ¶ added in v2.7.0
func ReflectStructFields(t reflect.Type) []reflect.StructField
ReflectStructFields returns the field names from the structure
func ReflectToBool ¶
ReflectToBool returns boolean from reflection
func ReflectToFloat64 ¶
ReflectToFloat64 returns float64 from reflection
func ReflectToInt64 ¶
ReflectToInt64 returns int64 from reflection
func ReflectToString
deprecated
func ReflectToType ¶
ReflectToType converts reflection valut to reflection type or returns nil
func ReflectToTypeContext ¶ added in v2.2.3
ReflectToType converts reflection valut to reflection type or returns nil
func ReflectTryToType ¶
ReflectTryToType converts reflection value to reflection type or returns error
func ReflectTryToTypeContext ¶ added in v2.2.3
func ReflectTryToTypeContext(ctx context.Context, srcVal reflect.Value, t reflect.Type, recursive bool, tags ...string) (any, error)
ReflectTryToTypeContext converts reflection value to reflection type or returns error
func SetStructFieldValue ¶
SetStructFieldValue puts value into the struct field
func SliceContext ¶ added in v2.2.3
SliceContext converts one type of array to other or resturns nil if not compatible
func StructAllFieldNames ¶ added in v2.7.2
StructAllFieldNames returns the field names from the structure including names from tags
func StructAllFieldNamesContext ¶ added in v2.7.2
StructAllFieldNamesContext returns the field names from the structure including names from tags
func StructContext ¶ added in v2.2.0
StructContext convert any input type into the target structure
func StructFieldNames ¶ added in v2.7.0
StructFieldNames returns the field names from the structure
func StructFieldTags ¶
StructFieldTags returns Map with key->tag matching
func StructFieldTagsUnsorted ¶
StructFieldTagsUnsorted returns field names and tag targets separately
func StructFieldValue ¶
StructFieldValue returns the value of the struct field
func StructWalk ¶ added in v2.8.0
func StructWalk(ctx context.Context, v any, walker structWalkerFunc, options ...WalkOption) error
StructWalk walks the struct recursively
func ToFloat64Slice
deprecated
func ToIntSlice
deprecated
func ToInterfaceSlice
deprecated
func ToMap ¶
ToMap cast your Source into the Destination type tag defines the tags name in the structure to map the keys
func ToMapContext ¶ added in v2.3.0
ToMap cast your Source into the Destination type tag defines the tags name in the structure to map the keys
func ToStringSlice
deprecated
func ToUint64ByReflect ¶
ToUint64ByReflect returns uint64 from reflection
func TryAnySlice ¶ added in v2.6.0
TryToAnySlice converts any input slice into destination type slice as return value
func TryAnySliceContext ¶ added in v2.2.3
TryAnySliceContext converts any input slice into destination type slice as return value
func TryCastContext ¶ added in v2.2.3
TryCastContext source type into the target type
func TryCastRecursive ¶
TryCastRecursive source type into the target type with recursive data converting
func TryCastRecursiveContext ¶ added in v2.2.3
TryCastRecursiveContext source type into the target type with recursive data converting
func TryCastValue ¶
TryCastValue source type into the target type
func TryCastValueContext ¶ added in v2.2.3
func TryCastValueContext[R any, T any](ctx context.Context, v T, recursive bool, tags ...string) (R, error)
TryCastValueContext source type into the target type
func TryCopyStruct ¶
TryCopyStruct convert any input type into the target structure
func TryCopyStructContext ¶ added in v2.2.0
TryCopyStructContext convert any input type into the target structure
func TryMap ¶
func TryMap[K comparable, V any](src any, tags ...string) (map[K]V, error)
TryMap creates new map to convert from soruce type
func TryMapContext ¶ added in v2.3.0
func TryMapContext[K comparable, V any](ctx context.Context, src any, tags ...string) (map[K]V, error)
TryMapContext creates new map to convert from soruce type
func TryMapCopy ¶
TryMapCopy converts source into destination or return error
func TryMapCopyContext ¶ added in v2.3.0
func TryMapCopyContext[K comparable, V any](ctx context.Context, dst map[K]V, src any, recursive bool, tags ...string) error
TryMapCopyContext converts source into destination or return error
func TryMapFrom ¶
TryMapFrom source creates new map to convert
func TryMapFromContext ¶ added in v2.3.0
func TryMapFromContext[K comparable, V any](ctx context.Context, src any, recursive bool, tags ...string) (map[K]V, error)
TryMapFrom source creates new map to convert
func TryMapRecursive ¶
func TryMapRecursive[K comparable, V any](src any, tags ...string) (map[K]V, error)
TryMapRecursive creates new map to convert from soruce type with recursive field processing
func TryMapRecursiveContext ¶ added in v2.3.0
func TryMapRecursiveContext[K comparable, V any](ctx context.Context, src any, tags ...string) (map[K]V, error)
TryMapRecursiveContext creates new map to convert from soruce type with recursive field processing
func TryReflectStr ¶
TryReflectStr converts reflection value to string
func TryReflectToString
deprecated
func TrySliceContext ¶ added in v2.2.3
func TrySliceContext[R any, S any](ctx context.Context, src []S, tags ...string) (res []R, err error)
TrySliceContext converts one type of array to other or resturns error
func TryToAnySliceContext ¶ added in v2.6.0
TryToAnySliceContext converts any input slice into destination type slice
func TryToContext ¶ added in v2.2.3
TryToContext cast any input type into the target
func TryToString
deprecated
func TryToTypeContext ¶ added in v2.2.3
TryToTypeContext cast any input type into the target reflection
Types ¶
type CastSetter ¶ added in v2.1.1
CastSetter interface from some type into the specific value
type StructWalkField ¶ added in v2.8.0
type StructWalkField interface { Name() string Tag(name string) string IsEmpty() bool RefValue() reflect.Value Value() any SetValue(ctx context.Context, v any) error }
StructWalkField is the type of the field visited by StructWalk
type StructWalkObject ¶ added in v2.8.0
type StructWalkObject interface { Parent() StructWalkObject RefValue() reflect.Value Struct() any }
type StructWalkOptions ¶ added in v2.8.0
type StructWalkOptions struct {
// contains filtered or unexported fields
}
StructWalkOptions is the options for StructWalk
func (*StructWalkOptions) PathName ¶ added in v2.8.0
func (w *StructWalkOptions) PathName(ctx context.Context, curObj StructWalkObject, field StructWalkField, path []string) string
PathName returns the path name of the current field
type WalkOption ¶ added in v2.8.0
type WalkOption func(w *StructWalkOptions)
WalkOption is the option for StructWalk
func WalkWithPathExtractor ¶ added in v2.8.0
func WalkWithPathExtractor(fn structWalkerNameFunc) WalkOption
WalkWithPathExtractor sets the path extractor for StructWalk
func WalkWithPathTag ¶ added in v2.8.0
func WalkWithPathTag(tagName string) WalkOption
WalkWithPathTag sets the path tag for StructWalk