rfutil

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Reflect utility package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone added in v0.4.0

func Clone(rv reflect.Value) (any, bool)

Clone Map, Slice or Array.

func CloneArray added in v0.4.0

func CloneArray(rv reflect.Value) (any, bool)

Clone Array.

func CloneMap added in v0.4.0

func CloneMap(rv reflect.Value) (any, bool)

Clone Map.

func CloneSlice added in v0.4.0

func CloneSlice(rv reflect.Value) (any, bool)

Clone Slice.

func CollectFields

func CollectFields(ptr any) []reflect.StructField

Get Fields of A Type

func CollectTypeFields

func CollectTypeFields(eleType reflect.Type) []reflect.StructField

Get Fields of A Type

func FindEmbedStruct

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

func FuncName

func FuncName(f any) string

Get name of func

func IsAnyNil

func IsAnyNil(v any) bool

func IsBasicKind

func IsBasicKind(k reflect.Kind) bool

func IsFieldExposed

func IsFieldExposed(fieldName string) bool

Check if field is exposed

func NewVar

func NewVar[T any]() T

func ReflectBasicValue

func ReflectBasicValue(rv reflect.Value) (any, bool)

func ReflectFuncName

func ReflectFuncName(fun any) string

func ReflectGenMap

func ReflectGenMap(t any) map[string]any

Construct Struct/Interface/Pointer values to map[string]any.

This method doesn't convert recursively.

func TypeName

func TypeName(t reflect.Type) string

func TypePkgPath added in v0.4.10

func TypePkgPath(f reflect.Type) string

func WalkTagShallow

func WalkTagShallow(ptr any, callbacks ...WalkTagCallback) error

Walk fields of *struct, won't go deeper even if the field is a struct.

Types

type ForEachField

type ForEachField func(index int, field reflect.StructField) (breakIteration bool)

type Introspector

type Introspector struct {
	Type   reflect.Type
	Fields []reflect.StructField
	// contains filtered or unexported fields
}

func Introspect

func Introspect(ptr any) Introspector

Create new Introspector

func (*Introspector) Field

func (it *Introspector) Field(fieldName string) (field reflect.StructField, isFieldFound bool)

Get field by name

func (*Introspector) FieldAt

func (it *Introspector) FieldAt(idx int) (field reflect.StructField)

Get field at index

func (*Introspector) FieldIdx

func (it *Introspector) FieldIdx(fieldName string) (index int, isFieldFound bool)

Get field index

func (*Introspector) IterFields

func (it *Introspector) IterFields(forEach ForEachField)

Iterate fields

func (*Introspector) Tag

func (it *Introspector) Tag(fieldName string, tagName string) (tag string, isFieldFound bool)

Get tag by of field

func (*Introspector) TagRetriever

func (it *Introspector) TagRetriever(fieldName string) (t TagRetriever, isFieldFound bool)

Get tag retriever for a field

type TagRetriever

type TagRetriever func(tagName string) string

type WalkTagCallback

type WalkTagCallback struct {
	Tag      string
	OnWalked func(tagVal string, fieldVal reflect.Value, fieldType reflect.StructField) error
}

Jump to

Keyboard shortcuts

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