Documentation
¶
Index ¶
- func ValidateAndBuildArguments(resourceProvider yamlkit.ResourceProvider, ...) ([]api.FunctionArgument, error)
- func WithLogger(ctx context.Context, logger *slog.Logger) context.Context
- type FunctionHandler
- func (fh *FunctionHandler) GetAttributes() []api.AttributeName
- func (fh *FunctionHandler) GetConverter() configkit.ConfigConverter
- func (fh *FunctionHandler) GetHandlerImplementation(functionName string) FunctionImplementation
- func (fh *FunctionHandler) GetPathRegistry() api.AttributeNameToResourceTypeToPathToVisitorInfoType
- func (fh *FunctionHandler) GetResourceProvider() yamlkit.ResourceProvider
- func (fh *FunctionHandler) Invoke(c echo.Context) error
- func (fh *FunctionHandler) InvokeCore(ctx context.Context, functionInvocation *api.FunctionInvocationRequest) (*api.FunctionInvocationResponse, error)
- func (fh *FunctionHandler) List(c echo.Context) error
- func (fh *FunctionHandler) ListCore() map[string]*FunctionRegistration
- func (fh *FunctionHandler) ListPaths(c echo.Context) error
- func (fh *FunctionHandler) RegisterFunction(functionName string, registration *FunctionRegistration) error
- type FunctionImplementation
- type FunctionImplementationArguments
- type FunctionRegistration
- type FunctionRegistry
- type ToolchainProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ValidateAndBuildArguments ¶
func ValidateAndBuildArguments(resourceProvider yamlkit.ResourceProvider, functionContext *api.FunctionContext, invocation *api.FunctionInvocation, f *api.FunctionSignature) ([]api.FunctionArgument, error)
ValidateAndBuildArguments validates function arguments and builds an in-order argument list. It returns the validated arguments or an error if validation fails.
It rewrites invocation.Arguments in place, naming positional arguments and replacing each value with its evaluated and converted form, so the caller must own that slice's backing array.
func WithLogger ¶ added in v0.11.13
WithLogger returns a context whose function invocations log to logger rather than to slog.Default(), so a program running functions in its own process decides where each invocation's log line goes without changing the process-wide default. Functions themselves log only at debug level, to slog.Default().
Types ¶
type FunctionHandler ¶
type FunctionHandler struct {
// contains filtered or unexported fields
}
func NewFunctionHandler ¶
func NewFunctionHandler(provider ToolchainProvider) *FunctionHandler
NewFunctionHandler creates a new FunctionHandler with the given provider. The provider supplies the converter and resource provider, and the compute-mutations function is automatically registered.
func (*FunctionHandler) GetAttributes ¶
func (fh *FunctionHandler) GetAttributes() []api.AttributeName
GetAttributes returns the list of registered attribute names from the path registry.
func (*FunctionHandler) GetConverter ¶
func (fh *FunctionHandler) GetConverter() configkit.ConfigConverter
func (*FunctionHandler) GetHandlerImplementation ¶
func (fh *FunctionHandler) GetHandlerImplementation(functionName string) FunctionImplementation
func (*FunctionHandler) GetPathRegistry ¶
func (fh *FunctionHandler) GetPathRegistry() api.AttributeNameToResourceTypeToPathToVisitorInfoType
GetPathRegistry returns the path registry from the resource provider.
func (*FunctionHandler) GetResourceProvider ¶
func (fh *FunctionHandler) GetResourceProvider() yamlkit.ResourceProvider
func (*FunctionHandler) InvokeCore ¶
func (fh *FunctionHandler) InvokeCore(ctx context.Context, functionInvocation *api.FunctionInvocationRequest) (*api.FunctionInvocationResponse, error)
func (*FunctionHandler) ListCore ¶
func (fh *FunctionHandler) ListCore() map[string]*FunctionRegistration
func (*FunctionHandler) RegisterFunction ¶
func (fh *FunctionHandler) RegisterFunction(functionName string, registration *FunctionRegistration) error
type FunctionImplementation ¶
type FunctionImplementation func(args FunctionImplementationArguments) (gaby.Container, any, error)
type FunctionImplementationArguments ¶
type FunctionImplementationArguments struct {
FunctionContext *api.FunctionContext
Options *api.FunctionOptions
ParsedData gaby.Container
ParsedOtherData map[api.OtherDataSource]gaby.Container
// OtherDataOrigins says where each document of an OtherData entry assembled from several
// Units came from, one per document of that entry in ParsedOtherData, in order.
OtherDataOrigins map[api.OtherDataSource][]api.OtherDataOrigin
Arguments []api.FunctionArgument
// Rows and GroupKey are what a reducer reads, the rows of one group of a reduce and the
// group's key, in place of ParsedData, which is then empty.
Rows api.RowList
GroupKey string
}
FunctionImplementationArguments bundles all inputs to a function implementation.
type FunctionRegistration ¶
type FunctionRegistration struct {
api.FunctionSignature
Function FunctionImplementation `json:"-"` // implementation
FunctionInit func() error `json:"-"` // optional one-time initialization
}
type FunctionRegistry ¶
type FunctionRegistry interface {
RegisterFunction(functionName string, registration *FunctionRegistration) error
GetHandlerImplementation(functionName string) FunctionImplementation
GetPathRegistry() api.AttributeNameToResourceTypeToPathToVisitorInfoType
GetAttributes() []api.AttributeName
GetConverter() configkit.ConfigConverter
GetResourceProvider() yamlkit.ResourceProvider
}
FunctionRegistry defines the interface for registering functions. This allows decoupling internal packages from the concrete FunctionHandler implementation.
type ToolchainProvider ¶
type ToolchainProvider interface {
configkit.ConfigConverter
yamlkit.ResourceProvider
GetToolchainType() workerapi.ToolchainType
}
ToolchainProvider combines the ConfigConverter and ResourceProvider interfaces. All built-in resource providers (k8skit, cubkit, etc.) implement both.