Documentation ¶
Index ¶
- func FunctionConnectionIDFromContext(ctx context.Context) (sdktypes.ConnectionID, error)
- func FunctionDataFromContext(ctx context.Context) []byte
- func FunctionValueFromContext(ctx context.Context) sdktypes.Value
- func UnpackArgs(args []sdktypes.Value, kwargs map[string]sdktypes.Value, dsts ...any) error
- type FuncOpt
- type Module
- type Optfn
- type VarOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FunctionConnectionIDFromContext ¶ added in v0.5.0
func FunctionConnectionIDFromContext(ctx context.Context) (sdktypes.ConnectionID, error)
func FunctionDataFromContext ¶
func UnpackArgs ¶
UnpackArgs unpacks the positional and keyword arguments into the supplied parameter variables. pairs is an alternating list of names and pointers to variables.
If the parameter name ends with "?", it is optional. If the parameter name ends with "=", it must be supplied in kwargs. If the parameter name ends with "?=" or "?="", it must be supplied in kwargs but is optional. If the parameter name ends with "=", it must be supplied in kwargs. If the parameter name starts with "**", the destination will accept all kwargs as a dict. If the parameter name starts with "*", the destination will aceppt all args as a list.
A nameless parameter can also be specified. That parameter must be a pointer to a struct. The function will use the member names of the struct as the parameter names. If the fields are tagged with `json:"..."` or `url:"..."`, the tag will be used as the parameter name. If the tag is "-", the field will be ignored. If the tag modifier is "omitempty", the field will be optional.
Example:
func SomeFunc(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error) { var ( x int y string args []int ) var st struct { Z int `json:"z"`} if err := UnpackArgs(args, kwargs, "x", &x, &st, "y=", &y, "*args", &args); err != nil { return err } ... }
(this function is heavily inspired by https://pkg.go.dev/go.starlark.net/starlark#UnpackArgs, it essentially does the same thing with some bells and whistles, but on autokitteh level)
Types ¶
type FuncOpt ¶
type FuncOpt func(*funcOpts) error
func WithFlag ¶
func WithFlag(flag sdktypes.FunctionFlag) FuncOpt
func WithFlags ¶
func WithFlags(flags ...sdktypes.FunctionFlag) FuncOpt
func WithFuncDesc ¶
func WithFuncDoc ¶
type Module ¶
type Module interface { Describe() sdktypes.Module Configure(ctx context.Context, xid sdktypes.ExecutorID, cid sdktypes.ConnectionID) (map[string]sdktypes.Value, error) sdkexecutor.Caller }
type Optfn ¶
type Optfn func(*moduleOpts) error
func ExportFunction ¶
func ExportFunction(name string, fn sdkexecutor.Function, fopts ...FuncOpt) Optfn