reflectx

package
v2.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: BSD-2-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForceGetValue

func ForceGetValue[T any](value reflect.Value) T

ForceGetValue force get the value hold by reflect.Value. The type param T must be the type that the Value stored, or this function will paniced.

func ForceSetValue

func ForceSetValue[T any](value *reflect.Value, v T) bool

ForceSetValue force set reflect.Value, no matter where value if readonly, not addressable, or has different types(but has same size). The type param T must be the type that the Value stored, or this function will paniced. This function returns true if the original value is modified(when and only when Value is indrect and addressable); Returns false otherwise, only the ptr field in Value is update, there is no standalone origional value, or origional value is not modified.

func GetPointer added in v2.3.0

func GetPointer(value reflect.Value) unsafe.Pointer

GetPointer return the pointer to reflect value.

func IsBytesType

func IsBytesType(t reflect.Type) bool

IsBytesType return if t is type for []byte

func StructToMap

func StructToMap(value any) map[string]any

StructToMap shallow convert struct to map, using field name as key, field value as map value. The Field name can be overridden using 'name' struct tag.

Note: only exported fields are set into map.

func TypeOf

func TypeOf[T any]() reflect.Type

TypeOf return reflect.Type for T

Types

type CallerInfo

type CallerInfo struct {
	Package  string // Package Name
	File     string // File Name
	Function string // Function Name
	LineNo   int    // Line number
}

CallerInfo is caller info

func GetCaller

func GetCaller(depth int) *CallerInfo

GetCaller return the caller info, param depth indicate the stack depth to the caller; for direct caller, depth is 1

Jump to

Keyboard shortcuts

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