gs_arg

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

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

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.

func Value

func Value(v any) gs.Arg

Value creates a fixed-value argument.

Types

type ArgList

type ArgList struct {
	// contains filtered or unexported fields
}

ArgList manages arguments for a function, supporting both fixed and variadic parameters.

func NewArgList

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

NewArgList validates and creates an ArgList for a function. It returns errors for invalid function types, mixed indexed/non-indexed args, or out-of-bounds indexes.

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) Condition

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

Condition adds pre-execution conditions to the binding.

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 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.

func (*Callable) Call

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

Call invokes the function with resolved arguments.

type CallableFunc

type CallableFunc = any

CallableFunc is a function that can be called.

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

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

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

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 fixed-value argument.

func (ValueArg) GetArgValue

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

GetArgValue returns the fixed value and validates type compatibility. It returns an error if the value type is incompatible with the target type.

Jump to

Keyboard shortcuts

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