Documentation ¶
Index ¶
- Constants
- type ContextBuilder
- func (builder *ContextBuilder) Build() (*VarContext, error)
- func (builder *ContextBuilder) BuildMap() (map[string]interface{}, error)
- func (builder *ContextBuilder) MergeDefaults(brokerVariables []DefaultVariable) *ContextBuilder
- func (builder *ContextBuilder) MergeEvalResult(key, template, resultType string) *ContextBuilder
- func (builder *ContextBuilder) MergeJsonObject(data json.RawMessage) *ContextBuilder
- func (builder *ContextBuilder) MergeMap(data map[string]interface{}) *ContextBuilder
- func (builder *ContextBuilder) MergeStruct(data interface{}) *ContextBuilder
- func (builder *ContextBuilder) SetEvalConstants(constants map[string]interface{}) *ContextBuilder
- type DefaultVariable
- type VarContext
- func (vc *VarContext) Error() error
- func (vc *VarContext) GetBool(key string) (res bool)
- func (vc *VarContext) GetInt(key string) (res int)
- func (vc *VarContext) GetString(key string) (res string)
- func (vc *VarContext) GetStringMapString(key string) (res map[string]string)
- func (vc *VarContext) ToJson() (json.RawMessage, error)
- func (vc *VarContext) ToMap() map[string]interface{}
Examples ¶
Constants ¶
const ( TypeObject = "object" TypeBoolean = "boolean" TypeArray = "array" TypeNumber = "number" TypeString = "string" TypeInteger = "integer" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextBuilder ¶
type ContextBuilder struct {
// contains filtered or unexported fields
}
ContextBuilder is a builder for VariableContexts.
func Builder ¶
func Builder() *ContextBuilder
Builder creates a new ContextBuilder for constructing VariableContexts.
func (*ContextBuilder) Build ¶
func (builder *ContextBuilder) Build() (*VarContext, error)
Build generates a finalized VarContext based on the state of the builder. Exactly one of VarContext and error will be nil.
func (*ContextBuilder) BuildMap ¶
func (builder *ContextBuilder) BuildMap() (map[string]interface{}, error)
BuildMap is a shorthand of calling build then turning the returned varcontext into a map. Exactly one of map and error will be nil.
Example ¶
_, e := Builder().MergeEvalResult("a", "${assert(false, \"failure!\")}", "string").BuildMap() fmt.Printf("Error: %v\n", e) m, _ := Builder().MergeEvalResult("a", "${1+1}", "string").BuildMap() fmt.Printf("Map: %v\n", m)
Output: Error: 1 error(s) occurred: couldn't compute the value for "a", template: "${assert(false, \"failure!\")}", assert: Assertion failed: failure! Map: map[a:2]
func (*ContextBuilder) MergeDefaults ¶
func (builder *ContextBuilder) MergeDefaults(brokerVariables []DefaultVariable) *ContextBuilder
MergeDefaults gets the default values from the given BrokerVariables and if they're a string, it tries to evaluet it in the built up context.
func (*ContextBuilder) MergeEvalResult ¶
func (builder *ContextBuilder) MergeEvalResult(key, template, resultType string) *ContextBuilder
MergeEvalResult evaluates the template against the templating engine and merges in the value if the result is not an error.
func (*ContextBuilder) MergeJsonObject ¶
func (builder *ContextBuilder) MergeJsonObject(data json.RawMessage) *ContextBuilder
MergeJsonObject converts the raw message to a map[string]interface{} and merges the values into the context. Blank RawMessages are treated like empty objects.
func (*ContextBuilder) MergeMap ¶
func (builder *ContextBuilder) MergeMap(data map[string]interface{}) *ContextBuilder
MergeMap inserts all the keys and values from the map into the context.
func (*ContextBuilder) MergeStruct ¶
func (builder *ContextBuilder) MergeStruct(data interface{}) *ContextBuilder
MergeStruct merges the given struct using its JSON field names.
func (*ContextBuilder) SetEvalConstants ¶
func (builder *ContextBuilder) SetEvalConstants(constants map[string]interface{}) *ContextBuilder
SetEvalConstants sets constants that will be available to evaluation contexts but not in the final output produced by the Build() call. These can be used to set values users can't overwrite mistakenly or maliciously.
type DefaultVariable ¶
type DefaultVariable struct { Name string `json:"name" yaml:"name"` Default interface{} `json:"default" yaml:"default"` Overwrite bool `json:"overwrite" yaml:"overwrite"` Type string `json:"type" yaml:"type"` }
DefaultVariable holds a value that may or may not be evaluated. If the value is a string then it will be evaluated.
func (*DefaultVariable) Validate ¶
func (dv *DefaultVariable) Validate() (errs *validation.FieldError)
Validate implements validation.Validatable.
type VarContext ¶
type VarContext struct {
// contains filtered or unexported fields
}
func (*VarContext) Error ¶
func (vc *VarContext) Error() error
Error gets the accumulated error(s) that this VarContext holds.
func (*VarContext) GetBool ¶
func (vc *VarContext) GetBool(key string) (res bool)
GetBool gets a boolean from the context, storing an error if the key doesn't exist or the variable couldn't be converted to a bool. Integers can behave like bools in C style, 0 is false. The strings "true" and "false" are also cast to their bool values.
func (*VarContext) GetInt ¶
func (vc *VarContext) GetInt(key string) (res int)
GetInt gets an integer from the context, storing an error if the key doesn't exist or the variable couldn't be converted to an int.
func (*VarContext) GetString ¶
func (vc *VarContext) GetString(key string) (res string)
GetString gets a string from the context, storing an error if the key doesn't exist or the variable couldn't be converted to a string.
func (*VarContext) GetStringMapString ¶
func (vc *VarContext) GetStringMapString(key string) (res map[string]string)
GetStringMapString gets map[string]string from the context, storing an error if the key doesn't exist or the variable couldn't be cast.
func (*VarContext) ToJson ¶
func (vc *VarContext) ToJson() (json.RawMessage, error)
ToJson gets the underlying JSON representaiton of the variable context.
func (*VarContext) ToMap ¶
func (vc *VarContext) ToMap() map[string]interface{}
ToMap gets the underlying map representaiton of the variable context.