Documentation ¶
Overview ¶
Package value provides a Value type that can be used to contain structured data of any type and comments that reference elements within it.
Example ¶
package main import ( "fmt" "github.com/aws-cloudformation/rain/cfn/value" ) func main() { data := map[string]interface{}{ "foo": map[string]interface{}{ "bar": "baz", }, } comments := map[interface{}]interface{}{ "": "Top-level comment", "foo": map[string]interface{}{ "": "Comment on foo", "bar": "Comment on bar", }, } value := value.New(data, comments) fmt.Println(value.Get(), "//", value.GetComment()) fmt.Println(value.Get("foo"), "//", value.GetComment("foo")) fmt.Println(value.Get("foo", "bar"), "//", value.GetComment("foo", "bar")) }
Output: map[foo:map[bar:baz]] // Top-level comment map[bar:baz] // Comment on foo baz // Comment on bar
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value holds structured data of any type and associated comments. Comments should be in the same format as the data it relates to with the exception that a map key of the empty string ("") will be taken to mean a comment related to the map as a whole
func New ¶
func New(data interface{}, comments map[interface{}]interface{}) Value
New creates a new Value from the supplied data and comments
func (Value) Get ¶
func (v Value) Get(path ...interface{}) interface{}
Get returns part of the Value's data by using a path given as a slice. The slice should contain map keys and array indexes that identify where the data is.
For eaxmple: '"foo", 1' would return the value from index 1 of an array that is stored with they key foo in a map.
func (Value) GetComment ¶
GetComment returns the comment matching the path provided. If no comment is found at the exact path, GetComment will try looking for a comment with a map key of "" as a special case where the associated data is a map