go_reflect

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: GPL-3.0 Imports: 3 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotAFunction                   = errors.New("not a function")
	ErrFunctionParameterCountMismatch = "function parameter count mismatch, expected %d, got %d"
	ErrFunctionParameterTypeMismatch  = "function parameter type mismatch on index %d, expected %s, got %s"
	ErrNilFunctionValue               = errors.New("nil function value")
)

Functions

func CheckFunction added in v0.2.2

func CheckFunction(fn interface{}, params ...interface{}) (
	*reflect.Value,
	*[]reflect.Value,
	error,
)

CheckFunction checks if a function is valid

func GetDereferencedType

func GetDereferencedType(instance interface{}) reflect.Type

GetDereferencedType returns the dereferenced type reflection

func GetDereferencedValue

func GetDereferencedValue(instance interface{}) reflect.Value

GetDereferencedValue returns the dereferenced value reflection

func GetType

func GetType(instance interface{}) reflect.Type

GetType returns the type reflection

func GetTypeName

func GetTypeName(typeReflection reflect.Type) string

GetTypeName returns the type name

func GetTypeOf added in v0.2.0

func GetTypeOf(bodyType interface{}) reflect.Type

GetTypeOf returns the type of the given bodyType

func GetValue

func GetValue(instance interface{}) reflect.Value

GetValue returns the value reflection

func NewInstance added in v0.2.1

func NewInstance(bodyType interface{}) interface{}

NewInstance creates a new instance of the given type

func NewInstanceFromType added in v0.2.1

func NewInstanceFromType(t reflect.Type) interface{}

NewInstanceFromType creates a new instance of the given type

func SafeCallFunction added in v0.2.3

func SafeCallFunction(fn interface{}, params ...interface{}) (
	[]interface{},
	error,
)

SafeCallFunction calls a function with some typed parameters after checking if the function is valid

func UnsafeCallFunction added in v0.2.3

func UnsafeCallFunction(fnValue *reflect.Value, paramsValues ...reflect.Value) (
	[]interface{},
	error,
)

UnsafeCallFunction calls a function with some typed parameters without checking if the function is valid

Types

type Reflection

type Reflection struct {
	// contains filtered or unexported fields
}

Reflection struct to hold reflection data

func NewDereferencedReflection

func NewDereferencedReflection(instance interface{}) *Reflection

NewDereferencedReflection creates a new reflection from a dereferenced instance

func NewReflection

func NewReflection(instance interface{}) *Reflection

NewReflection creates a new reflection from an instance

func (*Reflection) GetInstance

func (r *Reflection) GetInstance() interface{}

GetInstance returns the instance

func (*Reflection) GetReflectedType

func (r *Reflection) GetReflectedType() reflect.Type

GetReflectedType returns the reflected type

func (*Reflection) GetReflectedTypeName

func (r *Reflection) GetReflectedTypeName() string

GetReflectedTypeName returns the reflected type name

func (*Reflection) GetReflectedValue

func (r *Reflection) GetReflectedValue() reflect.Value

GetReflectedValue returns the reflected value

Jump to

Keyboard shortcuts

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