template

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parameter

type Parameter struct {
	Type    ParameterType `json:"type"`
	Default interface{}   `json:"default,omitempty"`
}

func (Parameter) Validate

func (d Parameter) Validate(assignment interface{}) error

type ParameterType

type ParameterType string
const (
	ParameterTypeBool   ParameterType = "bool"
	ParameterTypeNumber ParameterType = "number"
	ParameterTypeString ParameterType = "string"
	ParameterTypeArray  ParameterType = "array"
	ParameterTypeObject ParameterType = "object"
	ParameterTypeSecret ParameterType = "secret"

	SecretParameterLVal    = "$secret"
	SecretRefParameterLVal = "$secret_ref"
)

type ParameterTypeError

type ParameterTypeError struct {
	Expected string
	Actual   string
}

func (*ParameterTypeError) Error

func (e *ParameterTypeError) Error() string

type Parameters

type Parameters map[string]Parameter

func (Parameters) Bind

func (p Parameters) Bind(path tree.Path, bindings map[string]interface{}) (map[string]interface{}, error)

Bind will take in a set of bindings for parameters, type check them, and properly set defaults if necessary. It will then return the checked and defaulted set of parameter bindings.

type Template

type Template struct {
	Parameters Parameters
	Fields     map[string]interface{}
}

func (*Template) Evaluate

func (t *Template) Evaluate(path tree.Path, bindings map[string]interface{}) (map[string]interface{}, error)

Evaluate will crawl the Fields map and inject parameters into the values.

func (*Template) MarshalJSON

func (t *Template) MarshalJSON() ([]byte, error)

func (*Template) UnmarshalJSON

func (t *Template) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaller interface. The JSON should be an object. UnmarshalJSON will see if the object has a parameters field, and if it does try to Unmarshal it into a Parameters struct. If it succeeds it will use this struct as the Template's Parameters field. It will then use the rest of the fields of the object as the Template's Fields field.

Jump to

Keyboard shortcuts

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