actions

package
v0.0.0-...-bcbb5c0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2018 License: Apache-2.0 Imports: 3 Imported by: 10

Documentation

Overview

Package actions provides types and interfaces necessary to write action modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetActionModulesList

func GetActionModulesList() (moduleslist []string)

GetActionModulesList returns the list of all action modules.

func GetAllActions

func GetAllActions() map[string][]ActionDesc

func RegisterActionModule

func RegisterActionModule(name string, ac ActionModuleInterface)

RegisterActionModule registers the action module. Must be called from the init() of modules.

func RunAction

func RunAction(module string, action string, data map[string]interface{}) (map[string]interface{}, error)

RunAction calls the ActionHandler() of the module containing the action.

func SetupActionModules

func SetupActionModules(cfp configprovider.ConfigProviderInterface, actionslist []string)

SetupActionModules gets the configuration and calls the Setup() function of the modules specified by actionslist.

Types

type ActionDesc

type ActionDesc struct {
	In   []ArgType `json:"data_in"`
	Out  []ArgType `json:"data_out"`
	Name string    `json:"name"`
}

Type describing an action

type ActionModuleInterface

type ActionModuleInterface interface {
	Setup(config []byte) error
	Actions() (map[string][]ArgType, map[string][]ArgType)
	ActionHandler() func(string, map[string]interface{}) (map[string]interface{}, error)
}

ActionModuleInterface is the interface actions modules must implement. Setup() is called once when CSF starts and is used to configure and or init modules. Actions() returns a map of in and out parameters where Keys are actions names and values are lists of parameters of the given action. ActionHandler() is called everytime an action of the module needs to be Executed. It is basically a switch that call the right function.

type ArgType

type ArgType struct {
	T string `json:"type"`
	N string `json:"name"`
}

ArgType describes the different arguments and their types that an action needs as input. It is only used for humans so you can set arbitrary strings to describe the argument.

Jump to

Keyboard shortcuts

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