fix config decoder (#1142)

pull/1146/head
Tony Chen 4 years ago committed by GitHub
parent 81f96ee74d
commit 3795eddcf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      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 {

Loading…
Cancel
Save