From fa5b3ee9d9fd371e7c68efc6033b2c8c9e585346 Mon Sep 17 00:00:00 2001 From: Shu xian Date: Sun, 12 Jan 2020 04:50:09 +0800 Subject: [PATCH] config/reader.Values add Set for specific path merge (#1099) * add Set for specific path merge * add Set * add Del --- config/default.go | 22 ++++++++++++++++++++++ config/reader/reader.go | 2 ++ 2 files changed, 24 insertions(+) diff --git a/config/default.go b/config/default.go index aa9bf365..c01da98c 100644 --- a/config/default.go +++ b/config/default.go @@ -172,6 +172,28 @@ func (c *config) Get(path ...string) reader.Value { return newValue() } +func (c *config) Set(val interface{}, path ...string) { + c.Lock() + defer c.Unlock() + + if c.vals != nil { + c.vals.Set(val, path...) + } + + return +} + +func (c *config) Del(path ...string) { + c.Lock() + defer c.Unlock() + + if c.vals != nil { + c.vals.Del(path...) + } + + return +} + func (c *config) Bytes() []byte { c.RLock() defer c.RUnlock() diff --git a/config/reader/reader.go b/config/reader/reader.go index eee333e3..9d6fbb1a 100644 --- a/config/reader/reader.go +++ b/config/reader/reader.go @@ -18,6 +18,8 @@ type Reader interface { type Values interface { Bytes() []byte Get(path ...string) Value + Set(val interface{}, path ...string) + Del(path ...string) Map() map[string]interface{} Scan(v interface{}) error }