mirror of
https://github.com/astaxie/beego.git
synced 2024-12-22 17:10:50 +00:00
Merge pull request #3127 from kaka89/master
Refactor yaml config for support multilevel
This commit is contained in:
commit
3d3f2ed4c5
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user