sdkmodule

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 ...interface{}) 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 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.

Example:

	func SomeFunc(ctx context.Context, args []sdktypes.Value, kwargs map[string]sdktypes.Value) (sdktypes.Value, error) {
		var (
		  x int
		  y string
		  args []int
		)

		if err := UnpackArgs(args, kwargs, "x", &x, "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, but on autokitteh level and not starlark)

TODO: varargs.

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, config string) (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

func WithConfigAsData

func WithConfigAsData() Optfn

func WithDataFromConfig

func WithDataFromConfig(f func(string) ([]byte, error)) 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