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

Update yaml.go

add support for multilevel yaml config
This commit is contained in:
umasuo 2018-04-20 19:40:06 +08:00 committed by GitHub
parent f16688817a
commit ba89253e4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -285,9 +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, ".")
tmpData := c.data
for _, k := range keys {
if v, ok := tmpData[k]; ok {
switch v.(type) {
if v, ok := c.data[key]; ok { case map[string]interface{}:
return v, nil {
tmpData = v.(map[string]interface{})
}
default:
{
return v, nil
}
}
}
} }
return nil, fmt.Errorf("not exist key %q", key) return nil, fmt.Errorf("not exist key %q", key)
} }