gs_arg

package
v1.2.0-rc Latest Latest
Warning

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

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

Documentation

Overview

Package gs_arg provides a set of tools for working with function arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ArgList

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

ArgList represents a list of arguments for a function.

func NewArgList

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

NewArgList creates and validates an ArgList for the specified function.

type Callable

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

Callable wraps a function and its binding arguments.

func Bind

func Bind(fn CallableFunc, args []gs.Arg) (*Callable, error)

Bind creates a Callable by binding arguments to a function.

func MustBind

func MustBind(fn CallableFunc, args ...gs.Arg) *Callable

MustBind binds arguments to a function and panics if an error occurs.

func (*Callable) Call

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

Call invokes the function with its bound arguments processed in the IoC container.

func (*Callable) GetArgValue

func (r *Callable) GetArgValue(ctx gs.ArgContext, t reflect.Type) (reflect.Value, error)

func (*Callable) SetFileLine

func (r *Callable) SetFileLine(file string, line int) *Callable

SetFileLine sets the file and line number of the function call.

type CallableFunc

type CallableFunc = interface{}

CallableFunc is a function that can be called.

type IndexArg

type IndexArg struct {
	Idx int    // Index of the argument.
	Arg gs.Arg // The actual argument value.
}

IndexArg represents an argument that has an index.

func Index

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

Index creates an IndexArg with the given index and argument.

func (IndexArg) GetArgValue

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

GetArgValue is not implemented for IndexArg, it panics if called.

type OptionArg

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

OptionArg represents a binding for an option function argument.

func Option

func Option(fn CallableFunc, args ...gs.Arg) *OptionArg

Option creates a binding for an option function argument.

func (*OptionArg) Condition

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

Condition sets a condition for invoking the option function.

func (*OptionArg) GetArgValue

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

type TagArg

type TagArg struct {
	Tag string
}

TagArg represents an argument that has a tag for binding or autowiring.

func Tag

func Tag(tag string) TagArg

Tag creates a TagArg with the given tag.

func (TagArg) GetArgValue

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

GetArgValue returns the value of the argument based on its type.

type ValueArg

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

ValueArg represents an argument with a fixed value.

func Nil

func Nil() ValueArg

Nil returns a ValueArg with a value of nil.

func Value

func Value(v interface{}) ValueArg

Value returns a ValueArg with the specified value.

func (ValueArg) GetArgValue

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

GetArgValue returns the value of the fixed argument.

Jump to

Keyboard shortcuts

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