本文整理汇总了Golang中github.com/attic-labs/noms/go/types.Path.AddField方法的典型用法代码示例。如果您正苦于以下问题:Golang Path.AddField方法的具体用法?Golang Path.AddField怎么用?Golang Path.AddField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/attic-labs/noms/go/types.Path
的用法示例。
在下文中一共展示了Path.AddField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: diffMaps
func diffMaps(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.Map) {
wroteHeader := false
added, removed, modified := v2.Diff(v1)
for _, k := range added {
wroteHeader = writeHeader(w, wroteHeader, p)
line(w, addPrefix, k, v2.Get(k))
}
for _, k := range removed {
wroteHeader = writeHeader(w, wroteHeader, p)
line(w, subPrefix, k, v1.Get(k))
}
for _, k := range modified {
c1, c2 := v1.Get(k), v2.Get(k)
if canCompare(c1, c2) {
buf := bytes.NewBuffer(nil)
d.Exp.NoError(types.WriteEncodedValueWithTags(buf, k))
p1 := p.AddField(buf.String())
dq.PushBack(diffInfo{path: p1, key: k, v1: c1, v2: c2})
} else {
wroteHeader = writeHeader(w, wroteHeader, p)
line(w, subPrefix, k, v1.Get(k))
line(w, addPrefix, k, v2.Get(k))
}
}
writeFooter(w, wroteHeader)
}
示例2: diffStructs
func diffStructs(w io.Writer, p types.Path, v1, v2 types.Struct) {
changeChan := make(chan types.ValueChanged)
stopChan := make(chan struct{}, 1) // buffer size of 1, so this won't block if diff already finished
defer stop(stopChan)
go func() {
v2.Diff(v1, changeChan, stopChan)
close(changeChan)
}()
wroteHeader := false
for change := range changeChan {
fn := string(change.V.(types.String))
switch change.ChangeType {
case types.DiffChangeAdded:
wroteHeader = writeHeader(w, wroteHeader, p)
field(w, ADD, change.V, v2.Get(fn))
case types.DiffChangeRemoved:
wroteHeader = writeHeader(w, wroteHeader, p)
field(w, DEL, change.V, v1.Get(fn))
case types.DiffChangeModified:
f1 := v1.Get(fn)
f2 := v2.Get(fn)
if shouldDescend(f1, f2) {
diff(w, p.AddField(fn), types.String(fn), f1, f2)
} else {
wroteHeader = writeHeader(w, wroteHeader, p)
field(w, DEL, change.V, f1)
field(w, ADD, change.V, f2)
}
}
}
writeFooter(w, wroteHeader)
}
示例3: diffStructs
func diffStructs(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.Struct) {
changed := types.StructDiff(v1, v2)
wroteHeader := false
for _, field := range changed {
f1 := v1.Get(field)
f2 := v2.Get(field)
if canCompare(f1, f2) {
p1 := p.AddField(field)
dq.PushBack(diffInfo{path: p1, key: types.String(field), v1: f1, v2: f2})
} else {
wroteHeader = writeHeader(w, wroteHeader, p)
line(w, subPrefix, types.String(field), f1)
line(w, addPrefix, types.String(field), f2)
}
}
}
示例4: diffSets
func diffSets(dq *diffQueue, w io.Writer, p types.Path, v1, v2 types.Set) {
wroteHeader := false
added, removed := v2.Diff(v1)
if len(added) == 1 && len(removed) == 1 && canCompare(added[0], removed[0]) {
p1 := p.AddField(added[0].Hash().String())
dq.PushBack(diffInfo{path: p1, key: types.String(""), v1: removed[0], v2: added[0]})
} else {
for _, value := range removed {
wroteHeader = writeHeader(w, wroteHeader, p)
line(w, subPrefix, nil, value)
}
for _, value := range added {
wroteHeader = writeHeader(w, wroteHeader, p)
line(w, addPrefix, nil, value)
}
}
writeFooter(w, wroteHeader)
return
}