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
1 changed files with 16 additions and 2 deletions

View File

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