From 3795eddcf5624329cd3255e8e3f62f12ff2fc669 Mon Sep 17 00:00:00 2001 From: Tony Chen Date: Sat, 3 Jul 2021 15:30:19 +0800 Subject: [PATCH] fix config decoder (#1142) --- config/config.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index f078a1008..ccefd7f46 100644 --- a/config/config.go +++ b/config/config.go @@ -51,11 +51,15 @@ type config struct { func New(opts ...Option) Config { options := options{ logger: log.DefaultLogger, - decoder: func(kv *KeyValue, v map[string]interface{}) error { - if codec := encoding.GetCodec(kv.Format); codec != nil { - return codec.Unmarshal(kv.Value, &v) + decoder: func(src *KeyValue, target map[string]interface{}) error { + if src.Format == "" { + target[src.Key] = src.Value + return nil } - return fmt.Errorf("unsupported key: %s format: %s", kv.Key, kv.Format) + if codec := encoding.GetCodec(src.Format); codec != nil { + return codec.Unmarshal(src.Value, &target) + } + return fmt.Errorf("unsupported key: %s format: %s", src.Key, src.Format) }, } for _, o := range opts {