Help us shape the future of Go! Take the 2026 Go Developer Survey

actions

package
v0.49.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ActionTypes = []string{
	"gnmi",
	"http",
	"script",
	"template",
}
View Source
var Actions = map[string]Initializer{}

Functions

func BindLogger added in v0.46.0

func BindLogger(parent *slog.Logger, actionType, name string) *slog.Logger

BindLogger returns a non-nil *slog.Logger annotated with the action type and instance name. If parent is nil, a discarding logger is returned so callers never need a nil check.

func DecodeConfig

func DecodeConfig(src, dst interface{}) error

func Register

func Register(name string, initFn Initializer)

Types

type Action

type Action interface {
	// Init initializes an Action given its configuration and a list of options
	Init(cfg map[string]interface{}, opts ...Option) error
	// Run, well runs the action.
	// it takes an action Context which is made of:
	//  - `Input`  : an interface{} event message, target name added/deleted,...
	//  - `Env`    : a map[string]interface{} containing the output of previous actions
	//  - `Vars`   : a map[string]interface{} containing variables passed to the action
	//  - `Targets`: a map[string]*types.TargetConfig containing (if the action is ran by a loader)
	//               the currently known targets configurations
	Run(ctx context.Context, aCtx *Context) (interface{}, error)
	// NName returns the configured action name
	NName() string
	// WithTargets passes the known configured targets to the action when initialized
	WithTargets(map[string]*types.TargetConfig)
	// WithLogger passes the configured logger to the action
	WithLogger(*slog.Logger)
}

type Context

type Context struct {
	// Input event message, target name added/deleted,...
	Input interface{} `json:"Input,omitempty"`
	// Env used to store the output of a sequence of actions
	Env map[string]interface{} `json:"Env,omitempty"`
	// Vars contains the variables passed to the action
	Vars map[string]interface{} `json:"Vars,omitempty"`
	// a map of known targets configurations
	Targets map[string]*types.TargetConfig `json:"Targets,omitempty"`
}

Context defines an action execution context

type Initializer

type Initializer func() Action

type Option

type Option func(Action)

func WithLogger

func WithLogger(l *slog.Logger) Option

func WithTargets

func WithTargets(tcs map[string]*types.TargetConfig) Option

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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