diff

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

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

type Map map[string]Diff

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]

func (Map) Keys

func (m Map) Keys() []string

Keys returns the Map's keys

func (Map) Mode

func (m Map) Mode() Mode

Mode returns the Map's mode

func (Map) String

func (m Map) String() string

func (Map) Value

func (m Map) Value() interface{}

Value returns the Map's value

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 = "="
)

func (Mode) String

func (m Mode) String() string

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]

func (Slice) Mode

func (s Slice) Mode() Mode

Mode returns the Slice's mode

func (Slice) String

func (s Slice) String() string

func (Slice) Value

func (s Slice) Value() interface{}

Value returns the Slice's value

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

func (Value) Mode

func (v Value) Mode() Mode

Mode returns the Value's mode

func (Value) String

func (v Value) String() string

func (Value) Value

func (v Value) Value() interface{}

Value returns the Value's value

Jump to

Keyboard shortcuts

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