From b08ca73a6e738eca81c61de4b6eb78c24ad7efc7 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Sat, 3 Jun 2017 13:16:18 +0200 Subject: pkg/config: support null values --- pkg/config/config.go | 2 +- pkg/config/config_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'pkg') 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) { -- cgit mrf-deployment