Documentation
¶
Overview ¶
Package gs_arg provides implementations for argument resolution and binding used by the Go-Spring framework.
Key Features:
- Configuration property binding and dependency injection via struct tags.
- Precise positional binding through index-based arguments.
- Direct injection of fixed value arguments.
- Full support for variadic function parameters.
- Conditional execution with runtime evaluation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ArgList ¶
type ArgList struct {
// contains filtered or unexported fields
}
ArgList manages a collection of arguments for a target function, including both fixed and variadic parameters.
It supports two modes:
- Indexed mode: all arguments are provided with explicit positions (IndexArg).
- Sequential mode: arguments are provided in order (no explicit indices).
func NewArgList ¶
NewArgList validates and constructs an ArgList for the given function type.
Validation checks:
- fnType must be a function type.
- Cannot mix indexed and non-indexed arguments.
- Index values must be within valid parameter bounds.
type BindArg ¶
type BindArg struct {
// contains filtered or unexported fields
}
BindArg represents a bound function ready to be executed conditionally.
func Bind ¶
func Bind(fn CallableFunc, args ...gs.Arg) *BindArg
Bind creates a BindArg for a given function and its arguments. The function must have a valid bindable signature.
func (*BindArg) Condition ¶
Condition appends runtime conditions that must be satisfied before execution.
func (*BindArg) GetArgValue ¶
GetArgValue executes the function if all conditions are met and returns the result. It returns an invalid reflect.Value if conditions are not met. It also propagates errors from the function or condition checks.
func (*BindArg) SetFileLine ¶
SetFileLine records the source location of the Bind() call.
type Callable ¶
type Callable struct {
// contains filtered or unexported fields
}
Callable wraps a target function together with its resolved ArgList. It can be invoked at runtime with the correct arguments.
func NewCallable ¶
func NewCallable(fn CallableFunc, args []gs.Arg) (*Callable, error)
NewCallable creates a Callable by binding the given arguments to the function.
type IndexArg ¶
type IndexArg struct { Idx int //The positional index (0-based). Arg gs.Arg //The wrapped argument value. }
IndexArg represents an argument that is bound by its explicit position (index) in the target function’s parameter list.
func (IndexArg) GetArgValue ¶
GetArgValue for IndexArg should never be called directly. IndexArg is resolved by ArgList when assembling the function’s argument list. If called, it panics to indicate incorrect usage.
type TagArg ¶
type TagArg struct {
Tag string
}
TagArg represents an argument resolved using a tag for property binding or dependency injection.
func (TagArg) GetArgValue ¶
GetArgValue resolves the tag to a value based on the target type. - For primitive types (int, string), it binds from configuration. - For structs/interfaces, it wires dependencies from the container. It returns an error if the type is neither bindable nor injectable.
type ValueArg ¶
type ValueArg struct {
// contains filtered or unexported fields
}
ValueArg represents a constant (fixed) value argument that does not need any resolution or injection.
func (ValueArg) GetArgValue ¶
GetArgValue returns the fixed value wrapped by ValueArg. If the value is nil, it returns the zero value of the target type. If the value’s type is not assignable to the target type, it returns an error.