sdkmodule

package
v0.10.7 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

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 FunctionDataFromContext(ctx context.Context) []byte

func FunctionValueFromContext

func FunctionValueFromContext(ctx context.Context) sdktypes.Value

func UnpackArgs

func UnpackArgs(args []sdktypes.Value, kwargs map[string]sdktypes.Value, dsts ...any) error

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 WithArg

func WithArg(arg string) FuncOpt

func WithArgs

func WithArgs(args ...string) FuncOpt

func WithFlag

func WithFlag(flag sdktypes.FunctionFlag) FuncOpt

func WithFlags

func WithFlags(flags ...sdktypes.FunctionFlag) FuncOpt

func WithFuncDesc

func WithFuncDesc(desc string) FuncOpt

func WithFuncDoc

func WithFuncDoc(doc string) FuncOpt

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
}

func New

func New(optfns ...Optfn) Module

type Optfn

type Optfn func(*moduleOpts) error

func ExportFunction

func ExportFunction(name string, fn sdkexecutor.Function, fopts ...FuncOpt) Optfn

func ExportValue

func ExportValue(name string, vopts ...VarOpt) Optfn

type VarOpt

type VarOpt func(*varOpts) error

func WithNewValue

func WithNewValue(f func(xid sdktypes.ExecutorID, data []byte) (sdktypes.Value, error)) VarOpt

func WithValue

func WithValue(v sdktypes.Value) VarOpt

func WithVarDoc

func WithVarDoc(doc string) VarOpt

Jump to

Keyboard shortcuts

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