diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-06-03 13:16:18 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-06-03 13:16:18 +0200 |
| commit | b08ca73a6e738eca81c61de4b6eb78c24ad7efc7 (patch) | |
| tree | f42d64d78709b858d536df9020cf8b5ed9299e71 /pkg | |
| parent | b68d01eea0c45f14b6bd9b54485b7f7e287d008e (diff) | |
pkg/config: support null values
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/config/config.go | 2 | ||||
| -rw-r--r-- | pkg/config/config_test.go | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/pkg/config/config.go b/pkg/config/config.go index 03d4b283e..b31399713 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -63,7 +63,7 @@ func checkUnknownFieldsRec(data []byte, prefix string, typ reflect.Type) error { if !ok { return fmt.Errorf("unknown field '%v%v' in config", prefix, k) } - if field.Kind() == reflect.Slice && + if v != nil && field.Kind() == reflect.Slice && (field.PkgPath() != "encoding/json" || field.Name() != "RawMessage") { vv := reflect.ValueOf(v) if vv.Type().Kind() != reflect.Slice { diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 79836f39e..ee8a79661 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -157,6 +157,11 @@ func TestLoad(t *testing.T) { }, "", }, + { + `{"foo": null, "qux": null}`, + Config{}, + "", + }, } for i, test := range tests { t.Run(fmt.Sprint(i), func(t *testing.T) { |
