gs_arg

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

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

func Index

func Index(n int, arg gs.Arg) gs.Arg

Index creates an IndexArg with the given index and argument.

func Tag

func Tag(tag string) gs.Arg

Tag creates a TagArg with the given tag string.

func Value

func Value(v any) gs.Arg

Value creates a ValueArg from a fixed constant value.

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

func NewArgList(fnType reflect.Type, args []gs.Arg) (*ArgList, error)

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

func (arg *BindArg) Condition(conditions ...gs.Condition) *BindArg

Condition appends runtime conditions that must be satisfied before execution.

func (*BindArg) GetArgValue

func (arg *BindArg) GetArgValue(ctx gs.ArgContext, t reflect.Type) (reflect.Value, error)

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

func (arg *BindArg) SetFileLine(file string, line int)

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.

func (*Callable) Call

func (r *Callable) Call(ctx gs.ArgContext) ([]reflect.Value, error)

Call resolves all arguments and invokes the underlying function.

type CallableFunc

type CallableFunc = any

CallableFunc is an alias for any callable 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

func (arg IndexArg) GetArgValue(ctx gs.ArgContext, t reflect.Type) (reflect.Value, error)

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

func (arg TagArg) GetArgValue(ctx gs.ArgContext, t reflect.Type) (reflect.Value, error)

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

func (arg ValueArg) GetArgValue(ctx gs.ArgContext, t reflect.Type) (reflect.Value, error)

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.

Jump to

Keyboard shortcuts

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