diff --git a/core/config/config.go b/core/config/config.go index 908c65a5..a4a24fff 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -186,10 +186,6 @@ func (c *BaseConfiger) Strings(key string) ([]string, error) { return strings.Split(res, ";"), nil } -func (c *BaseConfiger) Unmarshaler(prefix string, obj interface{}, opt ...DecodeOption) error { - return errors.New("unsupported operation") -} - func (c *BaseConfiger) Sub(key string) (Configer, error) { return nil, errors.New("unsupported operation") } diff --git a/core/config/fake.go b/core/config/fake.go index 332eaf1e..3f6f4682 100644 --- a/core/config/fake.go +++ b/core/config/fake.go @@ -98,6 +98,10 @@ func (c *fakeConfigContainer) SaveConfigFile(filename string) error { return errors.New("not implement in the fakeConfigContainer") } +func (c *fakeConfigContainer) Unmarshaler(prefix string, obj interface{}, opt ...DecodeOption) error { + return errors.New("unsupported operation") +} + var _ Configer = new(fakeConfigContainer) // NewFakeConfig return a fake Configer diff --git a/core/config/ini.go b/core/config/ini.go index a78f0170..3d869eb4 100644 --- a/core/config/ini.go +++ b/core/config/ini.go @@ -27,6 +27,8 @@ import ( "strconv" "strings" "sync" + + "github.com/mitchellh/mapstructure" ) var ( @@ -505,6 +507,13 @@ func (c *IniConfigContainer) getdata(key string) string { return "" } +func (c *IniConfigContainer) Unmarshaler(prefix string, obj interface{}, opt ...DecodeOption) error { + if len(prefix) > 0 { + return errors.New("unsupported prefix params") + } + return mapstructure.Decode(c.data, opt) +} + func init() { Register("ini", &IniConfig{}) } diff --git a/go.mod b/go.mod index 697c9951..7527aa47 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/mattn/go-sqlite3 v2.0.3+incompatible github.com/mitchellh/mapstructure v1.3.3 github.com/opentracing/opentracing-go v1.2.0 - github.com/pelletier/go-toml v1.2.0 + github.com/pelletier/go-toml v1.8.1 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.7.0 github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 diff --git a/go.sum b/go.sum index 545dbae5..994d1ec4 100644 --- a/go.sum +++ b/go.sum @@ -157,6 +157,8 @@ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYr github.com/pelletier/go-toml v1.0.1/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= +github.com/pelletier/go-toml v1.8.1 h1:1Nf83orprkJyknT6h7zbuEGUEjcyVlCxSUGTENmNCRM= +github.com/pelletier/go-toml v1.8.1/go.mod h1:T2/BmBdy8dvIRq1a/8aqjN41wvWlN4lrapLU/GW4pbc= github.com/peterh/liner v1.0.1-0.20171122030339-3681c2a91233/go.mod h1:xIteQHvHuaLYG9IFj6mSxM0fCKrs34IrEQUhOYuGPHc= github.com/pkg/errors v0.8.0 h1:WdK/asTD0HN+q6hsWO3/vpuAkAr+tw6aNJNDFFf0+qw= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= diff --git a/server/web/config.go b/server/web/config.go index 47c9686e..404ac249 100644 --- a/server/web/config.go +++ b/server/web/config.go @@ -432,6 +432,10 @@ func newAppConfig(appConfigProvider, appConfigPath string) (*beegoAppConfig, err return &beegoAppConfig{innerConfig: ac}, nil } +func (b *beegoAppConfig) Unmarshaler(prefix string, obj interface{}, opt ...config.DecodeOption) error { + return b.innerConfig.Unmarshaler(prefix, obj, opt...) +} + func (b *beegoAppConfig) Set(key, val string) error { if err := b.innerConfig.Set(BConfig.RunMode+"::"+key, val); err != nil { return b.innerConfig.Set(key, val)