Merge pull request #3127 from kaka89/master

Refactor yaml config for support multilevel
This commit is contained in:
astaxie 2018-05-03 14:07:59 +08:00 committed by GitHub
commit 3d3f2ed4c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 2 deletions

View File

@ -285,9 +285,22 @@ func (c *ConfigContainer) getData(key string) (interface{}, error) {
if len(key) == 0 {
return nil, errors.New("key is empty")
}
keys := strings.Split(key, ".")
tmpData := c.data
for _, k := range keys {
if v, ok := tmpData[k]; ok {
switch v.(type) {
case map[string]interface{}:
{
tmpData = v.(map[string]interface{})
}
default:
{
return v, nil
}
if v, ok := c.data[key]; ok {
return v, nil
}
}
}
return nil, fmt.Errorf("not exist key %q", key)
}