Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
FieldName = lerr.Must(filter.Regex(`\p{Lu}(\p{L}|\p{N}|_)*`))
)
Functions ¶
This section is empty.
Types ¶
type Field ¶
type Field struct { FieldName string FieldInitilizer FuncType, FieldType filter.Type }
FieldInitilizer fulfills Initilizer. It contains the logic for validating the FieldName exists and getting that field from the magic data type. This simplifies the process of creating midware that sets a value on one field.
func NewField ¶
func NewField(fi FieldInitilizer, fieldName string) Field
NewField with the given values.
func NewFieldSetter ¶
type FieldInitilizer ¶
type FieldInitilizer interface {
InitilizeField(FuncType, reflect.Type) FieldInjector
}
FieldInitilizer is called by FieldInitilizer to handle any Type Reflection necessary in creating a FieldSetter. If no Type Reflection is necessary, a single type can fulfill FieldSetter, then FieldSetterInitilizer can just return itself.
type FieldInjector ¶
type FieldInjector interface {
InjectField(args []reflect.Value, field reflect.Value) (callback func([]reflect.Value), err error)
}
FieldInjector will set the value on 'set' generally from the request. This abstracts away the process of extracting a field from the magic data type.
func NewFieldInjector ¶
func NewFieldInjector(fn any) FieldInjector
NewFieldInjector takes a function and converts it to a field setter. The function must have 3 returns. The first is the value the field will be set to. The second is the callback function and the third is an error.
The arguments can either have a single argument of []reflect.Value in which case the arguments will be passed along. Or if it expects a specific argument pattern for the function, it can match the leading arguments. For instance, a FieldSetter on an HttpHandler could have arguments of (w http.ResponseWriter, r *http.Request)
type FuncType ¶
type FuncType interface { // Fn is the function type Fn() reflect.Type // DataType is a helper. The last argument of the function is a pointer // to a struct, DataType is that struct. Target() reflect.Type // contains filtered or unexported methods }
FuncType is a helper when invoking a FuncInitilizer. All that is necessisary for a FuncInitilizer is the function type but so much logic is dedicated to inspecting the Target that it's convenient to provide that seperatly.
type InitilizedFunc ¶
type InitilizedFunc struct {
// contains filtered or unexported fields
}
InitilizedFunc wraps a function so that a set of FuncInjector will run before calling the function and any callbacks will run after it returns.
func (*InitilizedFunc) Call ¶
func (ifn *InitilizedFunc) Call(args []reflect.Value) []reflect.Value
Call the InitilizedFunc, running the each FuncInjector before the wrapped function is called and then invoking the callbacks when the wrapped function returns.
func (*InitilizedFunc) Interface ¶
func (ifn *InitilizedFunc) Interface() any
Interface uses reflection to create a function without the target argument. This can be type cast to the function type and invoked as a normal function.
type Initilizer ¶
Initilizer represents a single injector. It inspects the FuncType to correctly apply the Injector. If the injection logic does not apply to the particular FuncType then nil is returned and the injector is not used with the given function. The injector may also use this initilization stage to dynamically change the logic in the returned FuncInjector rather than performing repetitive inspections on each invocation.
type Initilizers ¶
type Initilizers []Initilizer
FuncInitilizers allows a slice of FuncInitilizer to be applied to a function. All FuncInitilizer that return a non-nil value will be wrapped with the function to create an InitilizedFunc.
func (Initilizers) Apply ¶
func (fis Initilizers) Apply(fn any) *InitilizedFunc
Apply the FuncInitilizers to fn. If fn is not a valid function, nil is returned.
type Injector ¶
type Injector interface {
Inject(args []reflect.Value) (callback func(rets []reflect.Value), err error)
}
Injector holds injection logic that is invoked before a function is called. The args argument holds the values that will be passed into the function that is the subject of the injection. If a callback is returned, then the functions return values will be passed into the callback.