Documentation ¶
Overview ¶
Package runtime contains types which aid in the building of runtimes and runtime calls which can be constructed and invoked by the agent types.
The *Builder type aids in composing types which avoid having to do manual parsing to and from metadata fields on adagio.Node types.
The `runtime.Function()` is a handy function which takes a type with the behavior for parsing an incoming node (`Parse(*adagio.Node) error`) and running the function once parsed (`Run() (*adagio.Result, error)`) as separate calls and combines them in a agent.Function compatible implementation. This allows for a *runtime.Builder to be embedded into new Function definitions, which can then take on the responsibility of the `Parse(node) error` call. All you need to do is define and configure the named arguments of your function using the helper methods on the builder and then a single `Run()` implementation which takes care of invoking your functions behavior. For example, `builder.String(&str, "foo", false, "bar")` will add an argument "foo" which is not required and defaults to the value "bar".
The following is a contrived example of implementing the Runtime and Function types used the *Builder helper type.
package thing
import "github.com/georgemac/adagio/pkg/agent"
const name = "thing"
type Runtime struct {}
func (r Runtime) Name() string { return name }
func (r Runtime) BlankFunction() agent.Function { return runtime.Function(blankFunction()) }
func blankFunction() *Function { call := &Function{Builder: runtime.New(name)} call.String("string_arg", true, "default")(&call.StringArg) call.Strings("strings_arg", false, "many", "default")(&call.StringsArg) return call }
type Function struct { *runtime.Builder StringArg string StringsArg []string }
func NewFunction(stringArg string, extraStringArgs ...string) *Function { call := blackFunction() call.StringArg = stringArg call.StringsArg = extraStringArgs return call }
func (c *Function) Run() error { // do the things with the arguments }
Index ¶
- type Argument
- type ArgumentType
- type Builder
- func (b *Builder) Int64(v *int64, name string, required bool, defaultValue int64)
- func (b *Builder) JSON(v interface{}, name string, required bool)
- func (b *Builder) Name() string
- func (b *Builder) NewSpec(name string) (*adagio.Node_Spec, error)
- func (b *Builder) Parse(node *adagio.Node) error
- func (b *Builder) SetArgumentFromInput(argument, name string) error
- func (b *Builder) String(v *string, name string, required bool, defaultValue string)
- func (b *Builder) Strings(v *[]string, name string, required bool, defaultValues ...string)
- func (b *Builder) Time(v *time.Time, name string, required bool, defaultValue time.Time)
- type FunctionAdaptor
- type ParseRunner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Argument ¶
type Argument struct { Name string Type ArgumentType Required bool Defaults []string // contains filtered or unexported fields }
Argument is a structure which contains the properties of a argument used to call a runtime
func (*Argument) SetToDefault ¶
SetToDefault applies the default values to the argument
type ArgumentType ¶
type ArgumentType uint8
ArgumentType is a type of argument
const ( // StringArgumentType represents a string type argument StringArgumentType ArgumentType = iota // StringsArgumentType represents a slice of string types argument StringsArgumentType // Int64ArgumentType represents an int64 type argument Int64ArgumentType // TimeArgumentType represent a time.Time type argument TimeArgumentType // JSONArgumentType represents any value marshalled to and from using JSON JSONArgumentType )
func (ArgumentType) String ¶
func (t ArgumentType) String() string
String prints a string representation of the argument type
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a struct aids in both parsing and construction of runtimes and runtime request types
func NewBuilder ¶
NewBuilder constructs and configures a new runtime builder
func (*Builder) Int64 ¶
Int64 configures an int64 argument which will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()
func (*Builder) JSON ¶
JSON configures an argument which should be called with a pointer to any json marshallable type It will set the pointer on calls to builder.Parse() by calling unmarshal on the pointer and read the value at the end of the pointer and marshal it on calls to builder.NewSpec()
func (*Builder) NewSpec ¶
NewSpec constructs a Node_Spec based on the current state of the builders arguments
func (*Builder) Parse ¶
Parse parses the state from a node into the targets set on the builders arguments
func (*Builder) SetArgumentFromInput ¶
SetArgumentFromInput configures the argument to derives its value from the input paramertes of the node
func (*Builder) String ¶
String configures a string argument which when call with a string pointer will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()
func (*Builder) Strings ¶
Strings configures a string slice argument which when call with a string slice pointer will set the pointer on calls to builder.Parse() and read the value at the end of the pointer on calls to builder.NewSpec()
type FunctionAdaptor ¶
type FunctionAdaptor struct {
// contains filtered or unexported fields
}
FunctionAdaptor is the type used to covert a ParseRunner into a agent.Function compatable type
func Function ¶
func Function(runner ParseRunner) FunctionAdaptor
Function converts the provided ParseRunner into a agent.Function using the FunctionAdaptor wrapper type