Unverified Commit ba89253e authored by umasuo's avatar umasuo Committed by GitHub

Update yaml.go

add support for multilevel yaml config
parent f1668881
...@@ -285,9 +285,23 @@ func (c *ConfigContainer) getData(key string) (interface{}, error) { ...@@ -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, ".")
if v, ok := c.data[key]; ok { tmpData := c.data
return v, nil 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 nil, fmt.Errorf("not exist key %q", key) return nil, fmt.Errorf("not exist key %q", key)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment