actions

package
v0.39.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 4 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 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(*log.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 *log.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