1
0
Fork 0

Use full name for value field

This commit is contained in:
Gregory Eremin 2015-08-29 17:35:51 +03:00
parent e64a903c27
commit 9438d7bc19
2 changed files with 12 additions and 12 deletions

View File

@ -6,10 +6,10 @@ import (
) )
type field struct { type field struct {
Path string `json:"path"` Path string `json:"path"`
Name string `json:"name"` Name string `json:"name"`
Kind string `json:"kind"` Kind string `json:"kind"`
Val interface{} `json:"val"` Value interface{} `json:"val"`
} }
func extractFields(st interface{}, path string) []field { func extractFields(st interface{}, path string) []field {
@ -44,10 +44,10 @@ func extractFields(st interface{}, path string) []field {
reflect.Float64, reflect.Float64,
reflect.String: reflect.String:
res = append(res, field{ res = append(res, field{
Path: path + ftyp.Name, Path: path + ftyp.Name,
Name: ftyp.Name, Name: ftyp.Name,
Kind: kind.String(), Kind: kind.String(),
Val: fval.Interface(), Value: fval.Interface(),
}) })
default: default:
log.Printf("Field type %q not supported for field %q\n", kind, path+ftyp.Name) log.Printf("Field type %q not supported for field %q\n", kind, path+ftyp.Name)
@ -63,8 +63,8 @@ func diff(a, b interface{}) map[string][]interface{} {
res := make(map[string][]interface{}) res := make(map[string][]interface{})
for name, f := range af { for name, f := range af {
if bf[name].Val != f.Val { if bf[name].Value != f.Value {
res[name] = []interface{}{f.Val, bf[name].Val} res[name] = []interface{}{f.Value, bf[name].Value}
} }
} }

View File

@ -21,8 +21,8 @@ func TestExtractFields(t *testing.T) {
if f.Kind != kind { if f.Kind != kind {
t.Errorf("%s expected to be of kind %q, got %q", fname, kind, f.Kind) t.Errorf("%s expected to be of kind %q, got %q", fname, kind, f.Kind)
} }
if f.Val != val { if f.Value != val {
t.Errorf("%s expected to have value %q, got %q", fname, val, f.Val) t.Errorf("%s expected to have value %q, got %q", fname, val, f.Value)
} }
} else { } else {
t.Errorf("Missing %s field", fname) t.Errorf("Missing %s field", fname)