reflectext

package
v0.0.461 Latest Latest
Warning

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

Go to latest
Published: May 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertStructToMap added in v0.0.381

func ConvertStructToMap(v any, opts ...ConvertStructToMapOpt) map[string]any

func GetMapField added in v0.0.367

func GetMapField[TData any, TKey comparable](mapval any, key TKey) (TData, bool)

GetMapField gets the value of a map, without knowing the actual types (mapval is any) eg: x := langext.H{"K1": 665} GetMapPath[int](x, "K1") == 665

works with aliased types and autom. dereferences pointes

func GetMapPath added in v0.0.367

func GetMapPath[TData any](mapval any, path string) (TData, bool)

GetMapPath returns the value deep inside a hierahically nested map structure eg: x := langext.H{"K1": langext.H{"K2": 665}} GetMapPath[int](x, "K1.K2") == 665

func TryCast

func TryCast[T any](v any) (T, bool)

TryCast works similar to `v2, ok := v.(T)` Except it works through type alias'

func TryCastType

func TryCastType(v any, dest reflect.Type) (any, bool)

func Underlying

func Underlying(t reflect.Type) (ret reflect.Type)

Underlying returns the underlying type of t (without type alias)

https://github.com/golang/go/issues/39574#issuecomment-655664772

Types

type ConvertStructToMapOpt added in v0.0.416

type ConvertStructToMapOpt struct {
	KeepJsonMarshalTypes bool
	MaxDepth             *int
}

type PrimitiveStringSerializer

type PrimitiveStringSerializer struct{}

PrimitiveStringSerializer is used to serialize primitive types (and a few more) from and to string This is not really intended to be user facing, and more as a simple building block for other mechanisms supports:

  • golang primitives (ints, uints, floats, bool, string)
  • type aliases
  • time.Time
  • primitive.ObjectID

func (PrimitiveStringSerializer) ValueFromString

func (pss PrimitiveStringSerializer) ValueFromString(str string, outType reflect.Type) (any, error)

func (PrimitiveStringSerializer) ValueToString

func (pss PrimitiveStringSerializer) ValueToString(v any) (string, error)

Jump to

Keyboard shortcuts

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