func Diff(w io.Writer, v1, v2 types.Value) (err error) { dq := NewDiffQueue() di := diffInfo{path: types.NewPath().AddField("/"), v1: v1, v2: v2} dq.PushBack(di) err = d.Try(func() { for di, ok := dq.PopFront(); ok; di, ok = dq.PopFront() { p, key, v1, v2 := di.path, di.key, di.v1, di.v2 v1.Type().Kind() if v1 == nil && v2 != nil { line(w, addPrefix, key, v2) } if v1 != nil && v2 == nil { line(w, subPrefix, key, v1) } if !v1.Equals(v2) { if !canCompare(v1, v2) { line(w, subPrefix, key, v1) line(w, addPrefix, key, v2) } else { switch v1.Type().Kind() { case types.ListKind: diffLists(dq, w, p, v1.(types.List), v2.(types.List)) case types.MapKind: diffMaps(dq, w, p, v1.(types.Map), v2.(types.Map)) case types.SetKind: diffSets(dq, w, p, v1.(types.Set), v2.(types.Set)) case types.StructKind: diffStructs(dq, w, p, v1.(types.Struct), v2.(types.Struct)) default: panic("Unrecognized type in diff function") } } } } }) return }
func Diff(w io.Writer, v1, v2 types.Value) error { return diff(w, types.NewPath(), nil, v1, v2) }