dashdiffs

package
v4.5.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2017 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedDiffType occurs when an invalid diff type is used.
	ErrUnsupportedDiffType = errors.New("dashdiff: unsupported diff type")

	// ErrNilDiff occurs when two compared interfaces are identical.
	ErrNilDiff = errors.New("dashdiff: diff is nil")
)

Functions

This section is empty.

Types

type AsciiLine

type AsciiLine struct {
	// contains filtered or unexported fields
}

type BasicBlock

type BasicBlock struct {
	Title     string
	Old       interface{}
	New       interface{}
	Change    ChangeType
	Changes   []*BasicChange
	Summaries []*BasicSummary
	LineStart int
	LineEnd   int
}

A BasicBlock represents a top-level element in a basic diff.

type BasicChange

type BasicChange struct {
	Key       string
	Old       interface{}
	New       interface{}
	Change    ChangeType
	LineStart int
	LineEnd   int
}

A BasicChange represents the change from an old to new value. There are many BasicChanges in a BasicBlock.

type BasicDiff

type BasicDiff struct {
	LastIndent int
	Block      *BasicBlock
	Change     *BasicChange
	Summary    *BasicSummary
	// contains filtered or unexported fields
}

A BasicDiff holds the stateful values that are used when generating a basic diff from JSON tokens.

func (*BasicDiff) Basic

func (b *BasicDiff) Basic(lines []*JSONLine) []*BasicBlock

Basic transforms a slice of JSONLines into a slice of BasicBlocks.

type BasicFormatter

type BasicFormatter struct {
	// contains filtered or unexported fields
}

func NewBasicFormatter

func NewBasicFormatter(left interface{}) *BasicFormatter

func (*BasicFormatter) Format

func (b *BasicFormatter) Format(d diff.Diff) ([]byte, error)

Format takes the diff of two JSON documents, and returns the difference between them summarized in an HTML document.

type BasicSummary

type BasicSummary struct {
	Key       string
	Change    ChangeType
	Count     int
	LineStart int
	LineEnd   int
}

A BasicSummary represents the changes within a basic block that're too deep or verbose to be represented in the top-level BasicBlock element, or in the BasicChange. Instead of showing the values in this case, we simply print the key and count how many times the given change was applied to that element.

type ChangeType

type ChangeType int
const (
	ChangeNil ChangeType = iota
	ChangeAdded
	ChangeDeleted
	ChangeOld
	ChangeNew
	ChangeUnchanged
)

type DiffTarget

type DiffTarget struct {
	DashboardId      int64
	Version          int
	UnsavedDashboard *simplejson.Json
}

type DiffType

type DiffType int
const (
	DiffJSON DiffType = iota
	DiffBasic
	DiffDelta
)

func ParseDiffType

func ParseDiffType(diff string) DiffType

type JSONFormatter

type JSONFormatter struct {
	Lines []*JSONLine
	// contains filtered or unexported fields
}

func NewJSONFormatter

func NewJSONFormatter(left interface{}) *JSONFormatter

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(diff diff.Diff) (result string, err error)

type JSONLine

type JSONLine struct {
	LineNum   int         `json:"line"`
	LeftLine  int         `json:"leftLine"`
	RightLine int         `json:"rightLine"`
	Indent    int         `json:"indent"`
	Text      string      `json:"text"`
	Change    ChangeType  `json:"changeType"`
	Key       string      `json:"key"`
	Val       interface{} `json:"value"`
}

JSONLine contains the data required to render each line of the JSON diff and contains the data required to produce the tokens output in the basic diff.

type Options

type Options struct {
	OrgId    int64
	Base     DiffTarget
	New      DiffTarget
	DiffType DiffType
}

type Result

type Result struct {
	Delta []byte `json:"delta"`
}

func CalculateDiff

func CalculateDiff(options *Options) (*Result, error)

CompareDashboardVersionsCommand computes the JSON diff of two versions, assigning the delta of the diff to the `Delta` field.

Jump to

Keyboard shortcuts

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