Documentation
¶
Overview ¶
Package gs_arg provides implementation for function argument resolution and binding
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 arguments for a function, supporting both fixed and variadic parameters.
type BindArg ¶
type BindArg struct {
// contains filtered or unexported fields
}
BindArg represents a bound function with conditions for conditional execution.
func Bind ¶
func Bind(fn CallableFunc, args ...gs.Arg) *BindArg
Bind creates a binding for an option function. It panics on validation errors. `fn` is The target function (must return error or (T, error)). `args` is the bound arguments (indexed or non-indexed).
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 sets the source location of the Bind call.
type Callable ¶
type Callable struct {
// contains filtered or unexported fields
}
Callable wraps a function and its bound arguments for invocation.
func NewCallable ¶
func NewCallable(fn CallableFunc, args []gs.Arg) (*Callable, error)
NewCallable binds arguments to a function and creates a Callable. It returns errors for invalid function types or argument validation failures.
type IndexArg ¶
type IndexArg struct { Idx int //The positional index (0-based). Arg gs.Arg //The wrapped argument value. }
IndexArg represents an argument with an explicit positional index in the function signature.
func (IndexArg) GetArgValue ¶
GetArgValue panics if called directly. IndexArg must be processed by ArgList.
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 fixed-value argument.
func (ValueArg) GetArgValue ¶
GetArgValue returns the fixed value and validates type compatibility. It returns an error if the value type is incompatible with the target type.