Upgrade toml version

This commit is contained in:
Ming Deng 2020-10-14 00:24:22 +08:00
parent ccf873fa8b
commit 3fc21ae6ec
6 changed files with 20 additions and 5 deletions

View File

@ -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")
}

View File

@ -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

View File

@ -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{})
}

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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)