fix merge

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2020-12-20 00:36:07 +03:00
parent 44024bcd6a
commit b57c149c7f
3 changed files with 16 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"github.com/imdario/mergo"
"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/config"
)
@@ -62,7 +63,13 @@ func (c *fileConfig) Load(ctx context.Context) error {
var buf []byte
buf, err = ioutil.ReadAll(io.LimitReader(fp, int64(codec.DefaultMaxMsgSize)))
if err == nil {
err = c.opts.Codec.Unmarshal(buf, c.opts.Struct)
src, err := config.Zero(c.opts.Struct)
if err == nil {
err = c.opts.Codec.Unmarshal(buf, src)
if err == nil {
err = mergo.Merge(c.opts.Struct, src, mergo.WithOverride, mergo.WithTypeCheck, mergo.WithAppendSlice)
}
}
}
if err != nil && !c.opts.AllowFail {
return err