Actions - tympanix/artoodetoo GitHub Wiki

Example

The following is an example of an action which computes the sum of two numbers A and B.

package myaction

type MyAction struct {
	A   int `io:"input"`
	B   int `io:"input"`
	Sum int `io:"output"`
}

func init() {
	unit.Register(new(MyAction))
}

func (a *MyAction) Describe() string {
	return "An example action"
}

func (a *MyAction) Execute() {
	a.Sum = a.A + a.B
}

Input for the action is noted by the io:"input" tag, output by the io:"output" tag. The concrete action is implemented in the Execute() method. In this case, it computes the sum, and places the result into the Sum field, which is an output value for MyAction. The init() function is mandatory (by that name exactly) and registers the action into the application when the application starts.

Dont forget to import your package, in which your actions reside in the plugins.go file. In the above example the package name is myaction.

The name of the action will be the name of the package and the name of the action type. In this example the action name would be myaction.MyAction.