zreflect

package
v0.0.0-...-aa698f8 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2025 License: BSD-3-Clause Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	KindUndef     TypeKind = "undef"
	KindString             = "string"
	KindInt                = "int"
	KindFloat              = "float"
	KindBool               = "bool"
	KindStruct             = "struct"
	KindTime               = "time"
	KindByte               = "byte"
	KindMap                = "map"
	KindFunc               = "function"
	KindSlice              = "slice"
	KindArray              = "slice"
	KindInterface          = "interface"
	KindPointer            = "pointer"
)

Variables

View Source
var (
	TimeType = reflect.TypeOf(time.Time{})
)

Functions

func AnySetWithRelaxedNumbers

func AnySetWithRelaxedNumbers(to, from reflect.Value)

AnySetWithRelaxedNumbers sets int, float values from->to

func CopyAny

func CopyAny(v any) any

CopyVal makes a copy of rval. If rval is a pointer, it makes a copy of element and returns a pointer

func DeepCopy

func DeepCopy(destPtr, source any) error

func FlattenAll

func FlattenAll(f reflect.StructField) bool

func FlattenIfAnonymous

func FlattenIfAnonymous(f reflect.StructField) bool

func ForEachField

func ForEachField(istruct any, flatten func(f reflect.StructField) bool, got func(each FieldInfo) bool)

func GetTagAsMap

func GetTagAsMap(stag string) map[string][]string

func GetTagValuesForKey

func GetTagValuesForKey(stag reflect.StructTag, key string) (vals []string, ignore bool)

func GetZTags

func GetZTags(tagMap map[string][]string, tagName string) (keyVals []zstr.KeyValue, skip bool)

GetZTags get's all tags that are structured with k:v, parts etc, like zui

func HashAnyToInt64

func HashAnyToInt64(a interface{}, add string) int64

func IsRealSlice

func IsRealSlice(val reflect.Value) bool

func NewOfAny

func NewOfAny(a any) any

NewOfAny returns a new'ed item of that type. If a is a pointer, its element is used.

func SetStringToAny

func SetStringToAny(toPtr any, from string) error

func StructFieldNames

func StructFieldNames(istruct any, flatten func(f reflect.StructField) bool) []string

func Swap

func Swap[A any](a, b *A)

Types

type FieldInfo

type FieldInfo struct {
	FieldIndex   int // this is the index of the field _used_ field, not adding skipped, and increasing in anon
	ReflectValue reflect.Value
	StructField  reflect.StructField
}

func FieldForIndex

func FieldForIndex(istruct any, flatten func(f reflect.StructField) bool, index int) FieldInfo

func FieldForName

func FieldForName(istruct any, flatten func(f reflect.StructField) bool, name string) (FieldInfo, bool)

type Item

type Item struct {
	Kind            TypeKind
	BitSize         int
	TypeName        string
	FieldName       string
	Tag             string
	IsAnonymous     bool
	IsSlice         bool
	IsPointer       bool
	Address         any
	Package         string
	Value           reflect.Value
	Interface       any
	SimpleInterface any
	Children        []Item
}

func IterateStruct

func IterateStruct(istruct any, options Options) (item Item, err error)

type Options

type Options struct {
	UnnestAnonymous        bool
	Recursive              bool
	MakeSliceElementIfNone bool
}

type TypeKind

type TypeKind string

func KindFromReflectKindAndType

func KindFromReflectKindAndType(kind reflect.Kind, rtype reflect.Type) TypeKind

Jump to

Keyboard shortcuts

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