1
0
Fork 0

Implement callbacks

This commit is contained in:
Gregory Eremin 2015-08-29 15:29:56 +03:00
parent 6aa876c2a3
commit d4ec68d29e
3 changed files with 17 additions and 8 deletions

View File

@ -103,6 +103,14 @@ func triggerCallbacks(oldConf, newConf interface{}) {
return return
} }
for fname, d := range diff(oldConf, newConf) {
if cbs, ok := callbacks[fname]; ok {
for _, cb := range cbs {
cb(d[0], d[1])
}
}
}
return return
} }

View File

@ -10,6 +10,7 @@ type testConf struct {
Version float32 `json:"version"` Version float32 `json:"version"`
Database testDatabaseConf `json:"database"` Database testDatabaseConf `json:"database"`
} }
type testDatabaseConf struct { type testDatabaseConf struct {
Adapter string `json:"adapter"` Adapter string `json:"adapter"`
Host string `json:"host"` Host string `json:"host"`

View File

@ -16,16 +16,16 @@ func TestExtractFields(t *testing.T) {
} }
fields := extractFields(c, "") fields := extractFields(c, "")
testField := func(fieldName, kind string, val interface{}) { testField := func(fname, kind string, val interface{}) {
if f, ok := fields[fieldName]; ok { if f, ok := fields[fname]; ok {
if f.Kind != kind { if f.Kind != kind {
t.Errorf("%s expected to be of kind %q, got %q", fieldName, kind, f.Kind) t.Errorf("%s expected to be of kind %q, got %q", fname, kind, f.Kind)
} }
if f.Val != val { if f.Val != val {
t.Errorf("%s expected to have value %q, got %q", fieldName, val, f.Val) t.Errorf("%s expected to have value %q, got %q", fname, val, f.Val)
} }
} else { } else {
t.Errorf("Missing %s field", fieldName) t.Errorf("Missing %s field", fname)
} }
} }
@ -58,8 +58,8 @@ func TestDiff(t *testing.T) {
} }
d := diff(c1, c2) d := diff(c1, c2)
testField := func(fieldName string, oldVal, newVal interface{}) { testField := func(fname string, oldVal, newVal interface{}) {
if f, ok := d[fieldName]; ok { if f, ok := d[fname]; ok {
if f[0] != oldVal { if f[0] != oldVal {
t.Errorf("%s field old value was %q, not %q", oldVal, f[0]) t.Errorf("%s field old value was %q, not %q", oldVal, f[0])
} }
@ -67,7 +67,7 @@ func TestDiff(t *testing.T) {
t.Errorf("%s field new value was %q, not %q", newVal, f[1]) t.Errorf("%s field new value was %q, not %q", newVal, f[1])
} }
} else { } else {
t.Errorf("Expected %s field to have different values", fieldName) t.Errorf("Expected %s field to have different values", fname)
} }
} }