structure

package
v0.0.0-...-2f30d10 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 11 Imported by: 0

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 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 *MapOption) (any, error)

func ConvertToType

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

func ConvertToTypeWithOption

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

func ConvertToWithOption

func ConvertToWithOption[T any](from any, option *MapOption) (t T, err 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 *MapOption) error

func MapWithOption

func MapWithOption(from, to any, option *MapOption) 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 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 *MapOption) 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 MapOption

type MapOption struct {
	ZeroFields           bool
	WeaklyTypedInput     bool
	StringSplitSeparator string
}

func NewMapOption

func NewMapOption() *MapOption

type Mapper

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

type ParamsWalkFunc

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

type WalkFunc

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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