django_reflect

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTypeMismatch   = errors.New("type mismatch")
	ErrNotFunc        = errors.New("fn must be a function")
	ErrArgCount       = errors.New("argument count mismatch")
	ErrReturnCount    = errors.New("return count mismatch")
	ErrNilObject      = errors.New("object is nil")
	ErrMethodNotFound = errors.New("method not found")
)

Functions

func CastFunc

func CastFunc[OUT Function](fn any, opts ...func(*FuncConfig)) (OUT, error)

func ConvertToType

func ConvertToType(value reflect.Value, targetType reflect.Type) (reflect.Value, error)

func IsZero

func IsZero(value interface{}) bool

func Method

func Method[T Function](obj interface{}, name string, opts ...func(*FuncConfig)) (n T, err error)

Method retrieves a method from an object.

The generic type parameter must be the type of the method.

func RCastFunc

func RCastFunc(out reflect.Type, fn any, opts ...func(*FuncConfig)) (reflect.Value, error)

func RConvert

func RConvert(v *reflect.Value, t reflect.Type) (*reflect.Value, bool)

RConvert converts a reflect.Value to a different type.

If the value is not convertible to the type, the original value is returned.

If the pointer of `v` is invalid, a new value of type `t` is created, and the pointer is set to it, then the pointer is returned.

func RSet

func RSet(src, dst *reflect.Value, convert bool) bool

RSet sets a value from one reflect.Value to another.

If the destination value is not settable, this function will return false.

If the source value is not immediately assignable to the destination value, and the convert parameter is true, the source value will be converted to the destination value's type.

If the source value is not immediately assignable to the destination value, and the convert parameter is false, this function will return false.

func WrapWithContext

func WrapWithContext(ctx context.Context) func(*FuncConfig)

Types

type Func

type Func struct {
	Fn          Function
	Type        reflect.Type
	Value       reflect.Value
	ReturnTypes []reflect.Type
	BeforeExec  func(in []reflect.Value) error
	// contains filtered or unexported fields
}

func NewFunc

func NewFunc(fn Function, returns ...reflect.Type) *Func

func (*Func) AdheresTo

func (c *Func) AdheresTo(fn any) bool

func (*Func) Call

func (c *Func) Call(args ...interface{}) []interface{}

func (*Func) CallFunc

func (c *Func) CallFunc(in []reflect.Value) []interface{}

func (*Func) Requires

func (c *Func) Requires(index int, typ reflect.Type) *Func

func (*Func) Returns

func (c *Func) Returns(returns ...reflect.Type) *Func

type FuncConfig

type FuncConfig struct {
	// wrappers are applied before any validation occurs
	// this /could/ be used to set default values for parameters
	// such as context.Context, http.Request, etc.
	Wrappers []func(src reflect.Value, srcTyp reflect.Type, dst reflect.Type) (newSrc reflect.Value)

	// decorators are applied after validation occurs
	// you can use decorators to execute code before and after
	// the function is called. it is also possible
	// to modify the input and output parameters.
	Decorators []func(fn reflectFunc) reflectFunc
}

type Function

type Function = interface{} // func(...interface{}) -> Component

Jump to

Keyboard shortcuts

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