Documentation ¶
Overview ¶
Package diff provides the Diff class that can be used to compare CloudFormation templates
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Diff ¶
type Diff interface { // Mode represents the type of change in a Diff Mode() Mode // Value returns the value represented by the Diff Value() interface{} // String returns a string representation of a Diff String() string }
Diff is the common interface for the other types in this package.
A Diff represents the difference (or lack of difference) between two values
func New ¶
func New(old, new interface{}) Diff
New returns a Diff that represents the difference between two values of any type
To be able to compare slices and maps recursively, they must of type []interface{} and map[string]interface{}, respectively
Example ¶
package main import ( "fmt" "github.com/aws-cloudformation/rain/cfn/diff" ) func main() { original := map[string]interface{}{ "foo": []interface{}{ "bar", "baz", }, "quux": map[string]interface{}{ "mooz": "xyzzy", }, } fmt.Println(diff.New(original, map[string]interface{}{ "cake": "lie", })) }
Output: (|)map[(+)cake:lie (-)foo:[bar baz] (-)quux:map[mooz:xyzzy]]
type Map ¶
Map represents a difference between two maps
Example ¶
package main import ( "fmt" "github.com/aws-cloudformation/rain/cfn/diff" ) func main() { original := map[string]interface{}{"foo": "bar"} fmt.Println(diff.New(original, map[string]interface{}{"foo": "bar"})) fmt.Println(diff.New(original, map[string]interface{}{"foo": "baz"})) fmt.Println(diff.New(original, map[string]interface{}{})) fmt.Println(diff.New(original, map[string]interface{}{"foo": "bar", "baz": "quux"})) }
Output: (=)map[(=)foo:bar] (|)map[(>)foo:baz] (|)map[(-)foo:bar] (|)map[(+)baz:quux (=)foo:bar]
type Mode ¶
type Mode string
Mode represents a diff mode
const ( // Added represents a new value Added Mode = "+" // Removed represents a removed value Removed Mode = "-" // Changed represents a modified value Changed Mode = ">" // Involved represents a value that contains changes but is not wholly new itself Involved Mode = "|" // Unchanged represents a value that has not changed Unchanged Mode = "=" )
type Slice ¶
type Slice []Diff
Slice represents a difference between two slices
Example ¶
package main import ( "fmt" "github.com/aws-cloudformation/rain/cfn/diff" ) func main() { original := []interface{}{"foo"} fmt.Println(diff.New(original, []interface{}{"foo"})) fmt.Println(diff.New(original, []interface{}{"bar"})) fmt.Println(diff.New(original, []interface{}{})) fmt.Println(diff.New(original, []interface{}{"foo", "bar"})) }
Output: (=)[(=)foo] (|)[(>)bar] (|)[(-)foo] (|)[(=)foo (+)bar]
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents a difference between values of any type
Example ¶
package main import ( "fmt" "github.com/aws-cloudformation/rain/cfn/diff" ) func main() { fmt.Println(diff.New("foo", "foo")) fmt.Println(diff.New("foo", "bar")) }
Output: foo bar
Click to show internal directories.
Click to hide internal directories.