gcfg包增加SetViolenceCheck方法

This commit is contained in:
John
2018-07-01 00:38:35 +08:00
parent 59c0ee97e9
commit b167c03784
3 changed files with 13 additions and 2 deletions

View File

@ -33,7 +33,7 @@ type Json struct {
mu sync.RWMutex
p *interface{} // 注意这是一个指针
c byte // 层级分隔符,默认为"."
vc bool // 是否执行分隔符冲突检测(默认为false检测会比较影响检索效率)
vc bool // 层级检索是否执行分隔符冲突检测(默认为false检测会比较影响检索效率)
}
// 将变量转换为Json对象进行处理该变量至少应当是一个map或者array否者转换没有意义

View File

@ -47,7 +47,8 @@ func (p *Parser) SetSplitChar(char byte) {
p.json.SetSplitChar(char)
}
// 设置自定义的层级分隔符号
// 设置是否执行层级冲突检查,当键名中存在层级符号时需要开启该特性,默认为关闭。
// 开启比较耗性能,也不建议允许键名中存在分隔符,最好在应用端避免这种情况。
func (p *Parser) SetViolenceCheck(check bool) {
p.json.SetViolenceCheck(check)
}

View File

@ -26,6 +26,7 @@ type Config struct {
paths *gspath.SPath // 搜索目录路径
jsons *gmap.StringInterfaceMap // 配置文件对象
closed *gtype.Bool // 是否已经被close
vc *gtype.Bool // 层级检索是否执行分隔符冲突检测(默认为false检测会比较影响检索效率)
}
// 生成一个配置管理对象
@ -41,6 +42,7 @@ func New(path string, file...string) *Config {
paths : s,
jsons : gmap.NewStringInterfaceMap(),
closed : gtype.NewBool(),
vc : gtype.NewBool(),
}
}
@ -62,6 +64,13 @@ func (c *Config) SetPath(path string) error {
return nil
}
// 设置是否执行层级冲突检查,当键名中存在层级符号时需要开启该特性,默认为关闭。
// 开启比较耗性能,也不建议允许键名中存在分隔符,最好在应用端避免这种情况。
func (c *Config) SetViolenceCheck(check bool) {
c.vc.Set(check)
c.Reload()
}
// 添加配置管理器的配置文件搜索路径
func (c *Config) AddPath(path string) error {
if err := c.paths.Add(path); err != nil {
@ -91,6 +100,7 @@ func (c *Config) getJson(file...string) *gjson.Json {
return r.(*gjson.Json)
}
if j, err := gjson.Load(fpath); err == nil {
j.SetViolenceCheck(c.vc.Val())
c.addMonitor(fpath)
c.jsons.Set(fpath, j)
return j