structure

package module
v0.0.0-...-172eb0a Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 10 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddTypeAliasMap

func AddTypeAliasMap[Name any, Alias any]()

func Clone

func Clone[T any](value *T) *T

Clone is a generic function that creates a new instance of the given type T and assigns the value of the input parameter to the newly created instance. It then returns the pointer to the newly cloned instance.

Parameters: - value: a pointer to the value to be cloned

Returns: - a pointer to a newly created instance of type T, with the same value as the input parameter.

func CloneMap

func CloneMap[K comparable, V any](originalMap map[K]V) map[K]V

func ConvertTo

func ConvertTo[T any](from any) (T, error)

func ConvertToKind

func ConvertToKind(from any, toKind reflect.Kind) (any, error)

func ConvertToKindWithOption

func ConvertToKindWithOption(from any, toKind reflect.Kind, option *Option) (any, error)

func ConvertToType

func ConvertToType(from any, toType reflect.Type) (any, error)

func ConvertToTypeWithOption

func ConvertToTypeWithOption(from any, toType reflect.Type, option *Option) (any, error)

func ConvertToWithOption

func ConvertToWithOption[T any](from any, option *Option) (t T, e error)

func FieldHelper

func FieldHelper(s any) *fieldHelper

func GetFieldPath

func GetFieldPath(structField reflect.StructField, rootValues []reflect.Value) string

func Map

func Map(from, to any) error

func MapToValue

func MapToValue(from any, to reflect.Value) error

func MapToValueWithOption

func MapToValueWithOption(from any, to reflect.Value, option *Option) error

func MapWithOption

func MapWithOption(from, to any, option *Option) error

func Must

func Must[T any](t T, err error) T

func MustConvertTo

func MustConvertTo[T any](from any) T

func MustConvertToKind

func MustConvertToKind(from any, toKind reflect.Kind) any

func MustConvertToType

func MustConvertToType(from any, toType reflect.Type) any

func RegisterKindMapper

func RegisterKindMapper(from reflect.Kind, to reflect.Kind, mapper Mapper)

func RegisterMapper

func RegisterMapper[From any, To any](mapper Mapper)

func ReplaceMapper

func ReplaceMapper[From any, To any](mapper Mapper)

func SetField

func SetField(fieldValue reflect.Value, v any) error

func SetFieldBySetMethod

func SetFieldBySetMethod(fieldValue reflect.Value, v any, fieldStruct reflect.StructField, structValue reflect.Value) bool

func Value2ValueWithOption

func Value2ValueWithOption(from reflect.Value, to reflect.Value, option *Option) error

func WalkField

func WalkField(v any, walkFn WalkFunc) error

func WalkWithTagNames

func WalkWithTagNames(v any, tagNames []string, walkFn ParamsWalkFunc[map[string]string]) error

Types

type Error

type Error struct {
	Errors []error
}

Error implements the error interface and can represents multiple errors that occur in the course of a single decode. copy from github.com/mitchellh/mapstructure

func (*Error) Error

func (e *Error) Error() string

func (*Error) WrappedErrors

func (e *Error) WrappedErrors() []error

WrappedErrors implements the errwrap.Wrapper interface to make this return value more useful with the errwrap and go-multierror libraries.

type Mapper

type Mapper func(from reflect.Value, to reflect.Value, option *Option) error

type Option

type Option struct {
	ZeroFields           bool
	WeaklyTypedInput     bool
	StringSplitSeparator string

	// If ErrorUnused is true, then it is an error for there to exist
	// keys in the original map that were unused in the decoding process
	// (extra keys).
	ErrorUnused bool

	// If ErrorUnset is true, then it is an error for there to exist
	// fields in the result that were not set in the decoding process
	// (extra fields). This only applies to decoding to a struct. This
	// will affect all nested structs as well.
	ErrorUnset bool

	// Squash will squash embedded structs.  A squash tag may also be
	// added to an individual struct field using a tag.  For example:
	//
	//  type Parent struct {
	//      Child `mapping:",squash"`
	//  }
	Squash bool

	// The tag name that mapping reads for field names. This
	// defaults to "mapping"
	TagName string

	// IgnoreUntaggedFields ignores all struct fields without explicit
	// TagName, comparable to `mapstructure:"-"` as default behaviour.
	IgnoreUntaggedFields bool

	// MatchName is the function used to match the map key to the struct
	// field name or tag. Defaults to `strings.EqualFold`. This can be used
	// to implement case-sensitive tag values, support snake casing, etc.
	MatchName func(mapKey, fieldName string) bool
}

func NewOption

func NewOption() *Option

type ParamsWalkFunc

type ParamsWalkFunc[T any] func(fieldValue reflect.Value, structField reflect.StructField, rootValues []reflect.Value, params T) error

type ValueWrapper

type ValueWrapper interface{ Value() any }

type WalkFunc

type WalkFunc func(fieldValue reflect.Value, structField reflect.StructField, rootValues []reflect.Value) error

Jump to

Keyboard shortcuts

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