Skip to content

Commit

Permalink
Merge branch 'version/0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
hui.wang committed Jul 7, 2022
2 parents 1803878 + 4b0bd8e commit b39afcf
Show file tree
Hide file tree
Showing 12 changed files with 424 additions and 67 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG-0.3.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
### v0.3.18 🌈 (2022-05-07 18:05:47)
### v0.3.21 🌈 (2022-06-20 18:05:10)

#### 🤖 Tools
* 整理代码 ([ea167fb](https://github.com/sandwich-go/xconf/commit/ea167fbcded71a83df5b86a9918397f45677820f)) (<small>[祝黄清](huangqing.zhu@centurygame.com)@2022-06-20 18:05:10 &#43;0800 &#43;0800</small>)
* **sem**: make changelog ([1f3b253](https://github.com/sandwich-go/xconf/commit/1f3b253219899ca96487f767c471e7643cc4e3e0)) (<small>[祝黄清](huangqing.zhu@centurygame.com)@2022-06-20 17:59:58 &#43;0800 &#43;0800</small>)

### v0.3.20 (2022-06-20 17:55:25)

#### 🤖 Tools
* 增加MapStringUint64,MapUint64String,MapUint64Uint64的解析 ([bf1039c](https://github.com/sandwich-go/xconf/commit/bf1039c07998254d19dd0867f08413180c85e026)) (<small>[祝黄清](huangqing.zhu@centurygame.com)@2022-06-20 17:55:25 &#43;0800 &#43;0800</small>)
* **sem**: make changelog ([0d417ae](https://github.com/sandwich-go/xconf/commit/0d417ae04c428a2079706d11c4de224241b2d0f6)) (<small>[Daming Yang](daming.yang@centurygame.com)@2022-05-10 16:48:49 &#43;0800 &#43;0800</small>)

### v0.3.19 (2022-05-10 16:46:00)

#### 🛠 Refactor
* add error return value to ContentChange ([217843a](https://github.com/sandwich-go/xconf/commit/217843a2d2a9d583e12fc8843f347aaab01040e6)) (<small>[Daming Yang](daming.yang@centurygame.com)@2022-05-10 16:46:00 &#43;0800 &#43;0800</small>)

#### 🤖 Tools
* **sem**: make changelog ([1352355](https://github.com/sandwich-go/xconf/commit/1352355546bc84b0bbbcea9fed700fe1588617ce)) (<small>[hui.wang](hui.wang@funplus.com)@2022-05-07 18:06:04 &#43;0800 &#43;0800</small>)

### v0.3.18 (2022-05-07 18:05:47)

#### 🐛 Bug Fixed
* rm unused code ([e48f98a](https://github.com/sandwich-go/xconf/commit/e48f98a92fb92a5eea7a5718cc66fd63f81d5b08)) (<small>[hui.wang](hui.wang@funplus.com)@2022-05-07 18:05:47 &#43;0800 &#43;0800</small>)
Expand Down
8 changes: 4 additions & 4 deletions kv/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type Common struct {
}

// New 返回Common类型
func New(name string, implement loaderImplement, opts ...Option) *Common {
func New(_ string, implement loaderImplement, opts ...Option) *Common {
return &Common{implement: implement, fileMap: make(map[string]string), CC: NewOptions(opts...)}
}

Expand Down Expand Up @@ -101,13 +101,13 @@ func (c *Common) Watch(ctx context.Context, confPath string, onContentChange Con
if c.CC.OnWatchError == nil {
c.CC.OnWatchError = func(string, string, error) {}
}
c.implement.WatchImplement(ctx, confPath, func(name string, confPath string, data []byte) {
c.implement.WatchImplement(ctx, confPath, func(name string, confPath string, data []byte) error {
out, err := c.decode(data)
if err == nil {
onContentChange(name, confPath, out)
return
return onContentChange(name, confPath, out)
}
c.CC.OnWatchError(name, confPath, fmt.Errorf("got error :%w while decode using secconf", err))
return err
})
}

Expand Down
2 changes: 1 addition & 1 deletion kv/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// ContentChange kv数据发生变化时回调
type ContentChange = func(loaderName string, confPath string, content []byte)
type ContentChange = func(loaderName string, confPath string, content []byte) error

// WatchError kv.Loader.Watch发生错误时回调
type WatchError = func(loaderName string, confPath string, watchErr error)
Expand Down
10 changes: 5 additions & 5 deletions kv/xmem/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func New(opts ...kv.Option) (p *Loader, err error) {
}

// CloseImplement 实现common.loaderImplement.CloseImplement
func (p *Loader) CloseImplement(ctx context.Context) error { return nil }
func (p *Loader) CloseImplement(_ context.Context) error { return nil }

// GetImplement 实现common.loaderImplement.GetImplement
func (p *Loader) GetImplement(ctx context.Context, confPath string) ([]byte, error) {
func (p *Loader) GetImplement(_ context.Context, confPath string) ([]byte, error) {
p.dataMutex.Lock()
defer p.dataMutex.Unlock()
v, ok := p.data[confPath]
Expand All @@ -38,7 +38,7 @@ func (p *Loader) GetImplement(ctx context.Context, confPath string) ([]byte, err
}

// WatchImplement 实现common.loaderImplement.WatchImplement
func (p *Loader) WatchImplement(ctx context.Context, confPath string, onContentChange kv.ContentChange) {
func (p *Loader) WatchImplement(_ context.Context, confPath string, onContentChange kv.ContentChange) {
p.dataMutex.Lock()
defer p.dataMutex.Unlock()
p.onChanged[confPath] = onContentChange
Expand All @@ -53,7 +53,7 @@ func (p *Loader) Set(confPath string, data []byte) {
return
}
p.data[confPath] = data
if f, ok := p.onChanged[confPath]; ok {
f(p.Name(), confPath, data)
if f, ok := p.onChanged[confPath]; ok && f != nil {
_ = f(p.Name(), confPath, data)
}
}
78 changes: 38 additions & 40 deletions tests/replit/config/gen_config_optiongen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions xcmd/gen_config_optiongen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions xconf_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (x *XConf) notifyChanged() error {
return nil
}

func (x *XConf) onContentChanged(name string, confPath string, content []byte) {
func (x *XConf) onContentChanged(name string, confPath string, content []byte) (err error) {
x.cc.LogDebug(fmt.Sprintf("got update:%s", confPath))
defer func() {
if reason := recover(); reason == nil {
Expand All @@ -77,10 +77,12 @@ func (x *XConf) onContentChanged(name string, confPath string, content []byte) {
}()
unmarshal := GetDecodeFunc(filepath.Ext(confPath))
data := make(map[string]interface{})
err := unmarshal(content, data)
err = unmarshal(content, data)

xutil.PanicErrWithWrap(err, "unmarshal_error(%v) ", err)
xutil.PanicErr(x.commonUpdateAndNotify(func() error {
return x.mergeToDest(confPath, data)
err = x.mergeToDest(confPath, data)
return err
}))
return
}
11 changes: 4 additions & 7 deletions xflag/gen_options_optiongen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions xflag/vars/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,8 @@ func parseBool(s string) (bool, error) { return strconv.ParseBool(s) }
//go:generate gotemplate -outfmt gen_%v "../templates/xmap" "MapInt64String(int64,string,parseInt64,parseString,SetProviderByFieldType,StringValueDelim)"
//go:generate gotemplate -outfmt gen_%v "../templates/xmap" "MapInt64Int64(int64,int64,parseInt64,parseInt64,SetProviderByFieldType,StringValueDelim)"

//go:generate gotemplate -outfmt gen_%v "../templates/xmap" "MapStringUint64(string,uint64,parseString,parseUint64,SetProviderByFieldType,StringValueDelim)"
//go:generate gotemplate -outfmt gen_%v "../templates/xmap" "MapUint64String(uint64,string,parseUint64,parseString,SetProviderByFieldType,StringValueDelim)"
//go:generate gotemplate -outfmt gen_%v "../templates/xmap" "MapUint64Uint64(uint64,uint64,parseUint64,parseUint64,SetProviderByFieldType,StringValueDelim)"

//go:generate gotemplate -outfmt gen_%v "../templates/xmap" "MapStringTimeDuration(string,time.Duration,parseString,parseTimeDuration,SetProviderByFieldType,StringValueDelim)"
113 changes: 113 additions & 0 deletions xflag/vars/gen_MapStringUint64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b39afcf

Please sign in to comment.