Documentation ¶
Index ¶
- Constants
- func BuiltinActions() map[string]*sdkAct.Action
- func BuiltinPolicies() map[string]*sdkAct.Policy
- func BuiltinSignals() map[string]*sdkAct.Signal
- func Log(data map[string]any, params ...sdkAct.Parameter) (any, error)
- func Passthrough(map[string]any, ...sdkAct.Parameter) (any, error)
- func Terminate(_ map[string]any, params ...sdkAct.Parameter) (any, error)
- func WithLogger(logger zerolog.Logger) sdkAct.Parameter
- func WithResult(result map[string]any) sdkAct.Parameter
- type AsyncActionMessage
- type IPublisher
- type IRegistry
- type Publisher
- type Registry
- func (r *Registry) Add(policy *sdkAct.Policy)
- func (r *Registry) Apply(signals []sdkAct.Signal, hook sdkAct.Hook) []*sdkAct.Output
- func (r *Registry) Run(output *sdkAct.Output, params ...sdkAct.Parameter) (any, *gerr.GatewayDError)
- func (r *Registry) RunAll(result map[string]any) map[string]any
- func (r *Registry) ShouldTerminate(result map[string]any) bool
Constants ¶
const ( // TerminateDefaultParamCount is the default parameter count for the terminate action. TerminateDefaultParamCount = 2 // LogDefaultKeyCount is the default key count in the metadata for the log action. LogDefaultKeyCount = 3 // These are the keys used to pass the logger and the result to the built-in actions. LoggerKey = "__logger__" ResultKey = "__result__" )
Variables ¶
This section is empty.
Functions ¶
func BuiltinActions ¶
BuiltinActions returns a map of built-in actions.
func BuiltinPolicies ¶
BuiltinPolicies returns a map of built-in policies.
func BuiltinSignals ¶
BuiltinSignals returns a map of built-in signals.
func Passthrough ¶
Passthrough is a built-in action that always returns true and no error.
func Terminate ¶
Terminate is a built-in action that terminates the connection if the terminate signal is true and the policy is set to "stop". The action can optionally receive a result parameter.
func WithLogger ¶
WithLogger returns a parameter with the Logger to be used by the action. This is automatically prepended to the parameters when running an action.
Types ¶
type AsyncActionMessage ¶ added in v0.9.6
func (*AsyncActionMessage) Decode ¶ added in v0.9.6
func (msg *AsyncActionMessage) Decode(data []byte) error
func (*AsyncActionMessage) Encode ¶ added in v0.9.6
func (msg *AsyncActionMessage) Encode() ([]byte, error)
Encode marshals the AsyncActionMessage struct to JSON bytes.
type IPublisher ¶ added in v0.9.6
type Publisher ¶ added in v0.9.6
func NewPublisher ¶ added in v0.9.6
type Registry ¶
type Registry struct { Logger zerolog.Logger // Timeout for policy evaluation. PolicyTimeout time.Duration // Default timeout for running actions DefaultActionTimeout time.Duration // TaskPublisher is the publisher for async actions. // if not given, will invoke simple goroutine to run async actions TaskPublisher *Publisher Signals map[string]*sdkAct.Signal Policies map[string]*sdkAct.Policy Actions map[string]*sdkAct.Action DefaultPolicyName string DefaultPolicy *sdkAct.Policy DefaultSignal *sdkAct.Signal }
Registry keeps track of all policies and actions.
func NewActRegistry ¶
NewActRegistry creates a new act registry with the specified default policy and timeout and the builtin signals, policies, and actions.
func (*Registry) Run ¶
func (r *Registry) Run( output *sdkAct.Output, params ...sdkAct.Parameter, ) (any, *gerr.GatewayDError)
Run runs the function associated with the output.MatchedPolicy and returns its result. If the action is synchronous, the result is returned immediately. If the action is asynchronous, the result is nil and the error is ErrAsyncAction, which is a sentinel error to indicate that the action is running asynchronously.
func (*Registry) RunAll ¶ added in v0.9.9
RunAll run all the actions in the outputs and returns the end result.
func (*Registry) ShouldTerminate ¶ added in v0.9.9
ShouldTerminate checks if any of the actions are terminal, indicating that the request should be terminated. This is an optimization to avoid executing the actions' functions unnecessarily. The __terminal__ field is only set when an action intends to terminate the request.