Documentation
¶
Overview ¶
Package funcs implements function call by its name.
Index ¶
- Constants
- Variables
- func Call(name string, params ...interface{}) (err error)
- func GetFuncIn(name string, i int) interface{}
- func ReflectValueOf(param interface{}) reflect.Value
- func Register(obj interface{}) (err error)
- func RegisterName(name string, obj interface{}) error
- func Services() []string
- func SetLog(enable bool)
- func ValueCall(name string, in ...Value) (err error)
- type Func
- func (f *Func) Call(params ...interface{}) (err error)
- func (f *Func) GetIn(i int) interface{}
- func (f *Func) GetValueIn(i int) Value
- func (f *Func) NumCalls() (n int64)
- func (f *Func) NumIn() int
- func (f *Func) NumOut() int
- func (f *Func) ValueCall(in ...Value) (err error)
- func (f *Func) WithContext() bool
- type Funcs
- func (f *Funcs) Call(name string, params ...interface{}) (err error)
- func (f *Funcs) GetFunc(name string) (F *Func)
- func (f *Funcs) GetFuncIn(name string, i int) interface{}
- func (f *Funcs) GetFuncValueIn(name string, i int) Value
- func (f *Funcs) Register(obj interface{}) (err error)
- func (f *Funcs) RegisterName(name string, obj interface{}) (err error)
- func (f *Funcs) Services() []string
- func (f *Funcs) SetLog(enable bool)
- func (f *Funcs) ValueCall(name string, in ...Value) (err error)
- type Value
Constants ¶
const LogPrefix = "funcs"
LogPrefix is the prefix of log.
Variables ¶
var ( //ZeroValue is the Value of zero ZeroValue = Value{} //ErrNumParams is the error of params number. ErrNumParams = errors.New("The number of params is not adapted") //ErrObject is the error of nil. ErrObject = errors.New("The object is nil") //DefalutFuncs is the defalut Funcs. DefalutFuncs = New() )
Functions ¶
func Call ¶
Call calls the function with the input arguments. For example, Call("v",arg1,arg2) represents the Go call v(arg1,arg2). Call panics if v's Kind is not Func. As in Go, each input argument must be assignable to the type of the function's corresponding input parameter.
func ReflectValueOf ¶
ReflectValueOf returns a new reflect.Value.
func Register ¶
func Register(obj interface{}) (err error)
Register publishes the set of struct's methods in the DefalutFuncs. If the function has a context.Context parameter, the context.Context must be the first parameter of the function.
func RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the struct's concrete type.
Types ¶
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func defines the struct of func.
func (*Func) GetValueIn ¶
GetValueIn returns the Value of index'th input parameter by index.
func (*Func) WithContext ¶ added in v1.0.1
WithContext returns whether calling with context.
type Funcs ¶
type Funcs struct {
// contains filtered or unexported fields
}
Funcs defines the struct of Funcs.
func (*Funcs) Call ¶
Call calls the function with the input arguments. For example, Call("v",arg1,arg2) represents the Go call v(arg1,arg2). Call panics if v's Kind is not Func. As in Go, each input argument must be assignable to the type of the function's corresponding input parameter.
func (*Funcs) GetFuncIn ¶
GetFuncIn returns index'th input parameter by name and index in the Funcs.
func (*Funcs) GetFuncValueIn ¶
GetFuncValueIn returns the Value of index'th input parameter by name and index in the Funcs.
func (*Funcs) Register ¶
Register publishes the set of struct's methods in the Funcs. If the function has a context.Context parameter, the context.Context must be the first parameter of the function.
func (*Funcs) RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the struct's concrete type.
type Value ¶
Value is the reflection interface to a Go value.
func GetFuncValueIn ¶
GetFuncValueIn returns the Value of index'th input parameter by name and index in the DefalutFuncs.