Example #1
0
func (f *AsciiFormatter) formatArray(left []interface{}, df diff.Diff) {
	f.printIndent(AsciiSame)
	f.println("[")
	f.push("ROOT", len(left), true)
	f.processArray(left, df.Deltas())
	f.pop()
	f.printIndent(AsciiSame)
	f.println("]")
}
Example #2
0
func (f *AsciiFormatter) formatObject(left map[string]interface{}, df diff.Diff) {
	f.printIndent(AsciiSame)
	f.println("{")
	f.push("ROOT", len(left), false)
	f.processObject(left, df.Deltas())
	f.pop()
	f.printIndent(AsciiSame)
	f.println("}")
}
Example #3
0
func (f *DeltaFormatter) Format(diff diff.Diff) (result string, err error) {
	jsonObject, err := f.formatObject(diff.Deltas())
	if err != nil {
		return "", err
	}
	var resultBytes []byte
	if f.PrintIndent {
		resultBytes, err = json.MarshalIndent(jsonObject, "", "  ")
	} else {
		resultBytes, err = json.Marshal(jsonObject)
	}
	if err != nil {
		return "", err
	}

	return string(resultBytes), nil
}
Example #4
0
func (f *DeltaFormatter) FormatAsJson(diff diff.Diff) (json map[string]interface{}, err error) {
	return f.formatObject(diff.Deltas())
}