1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 23:01:28 +00:00

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

View File

@ -285,10 +285,23 @@ func (c *ConfigContainer) getData(key string) (interface{}, error) {
if len(key) == 0 { if len(key) == 0 {
return nil, errors.New("key is empty") return nil, errors.New("key is empty")
} }
keys := strings.Split(key, ".")
if v, ok := c.data[key]; ok { 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 return v, nil
} }
}
}
}
return nil, fmt.Errorf("not exist key %q", key) return nil, fmt.Errorf("not exist key %q", key)
} }