Documentation ¶
Overview ¶
Package template contains functions for rendering templates.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ErrScopeMergeConflict ¶
type ErrScopeMergeConflict struct {
Path string
}
ErrScopeMergeConflict indicates that a conflict occurred when merging two scopes at the specified path.
func (ErrScopeMergeConflict) Error ¶
func (e ErrScopeMergeConflict) Error() string
type Scope ¶
type Scope map[interface{}]interface{}
Scope represents a single lexical value scope. Scopes can be nested.
func (Scope) Flat ¶
Example ¶
package main import ( "fmt" "github.com/tooploox/oya/pkg/template" ) func main() { scope := template.Scope{ "foo": map[interface{}]interface{}{ "bar": "baz", "qux": []interface{}{ "1", "2", 3, }, "abc": map[string]interface{}{ "123": true, }, }, } flattened := scope.Flat() fmt.Println("foo.bar:", flattened["foo.bar"]) _, ok := flattened["foo"] fmt.Println("foo exists?", ok) fmt.Println("foo.qux.0:", flattened["foo.qux.0"]) fmt.Println("foo.qux.1:", flattened["foo.qux.1"]) fmt.Println("foo.qux.2:", flattened["foo.qux.2"]) fmt.Println("foo.abc.123:", flattened["foo.abc.123"]) }
Output: foo.bar: baz foo exists? false foo.qux.0: 1 foo.qux.1: 2 foo.qux.2: 3 foo.abc.123: true
func (Scope) GetScopeAt ¶
GetScopeAt returns scope at the specified path. If path doesn't exist or points to a value that cannot be interpreted as a Scope (see ParseScope), the function signals an error.
func (Scope) Merge ¶
Merge combines two scopes together. If a key appears in both scopes, the other scope wins.
func (Scope) Replace ¶
Replace replaces contents of this scope with keys and values of the other one.
func (Scope) UpdateScopeAt ¶
UpdateScopeAt transforms a scope pointed to by the path (e.g. "foo.bar.baz"). It will create scopes along the way if they don't exist. In case the value pointed by the path already exists and cannot be interpreted as a Scope (see ParseScope), the function signals ErrScopeMergeConflict.