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("]") }
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("}") }
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 }
func (f *DeltaFormatter) FormatAsJson(diff diff.Diff) (json map[string]interface{}, err error) { return f.formatObject(diff.Deltas()) }