github.com/hedzr/evendeep@v0.4.8/diff/update.go (about) 1 package diff 2 3 import ( 4 "fmt" 5 "reflect" 6 7 "github.com/hedzr/evendeep/typ" 8 ) 9 10 type Update struct { 11 Old, New typ.Any // string 12 Typ string 13 } 14 15 func (n Update) String() string { 16 if n.Old == nil { 17 return fmt.Sprintf("%#v", n.New) 18 } 19 if n.New == nil { 20 return fmt.Sprintf("%#v -> nil", n.Old) 21 } 22 23 a, b := reflect.ValueOf(n.Old), reflect.ValueOf(n.New) 24 if a.Kind() != b.Kind() { 25 return fmt.Sprintf("%#v (%v) -> %#v (%v)", n.Old, a.Kind(), n.New, b.Kind()) 26 } 27 28 if n.Typ != "" { 29 return fmt.Sprintf("%#v -> %#v (typ = %q)", n.Old, n.New, n.Typ) 30 } 31 32 return fmt.Sprintf("%#v -> %#v", n.Old, n.New) 33 }