Compare commits

..

No commits in common. "master" and "v1.1.0" have entirely different histories.

3 changed files with 3 additions and 16 deletions

View File

@ -85,9 +85,11 @@ func recursiveParse(item string, v interface{}) interface{} {
if item == "" {
return v
}
chunks := strings.SplitN(item, ".", 2)
if n, err := strconv.Atoi(chunks[0]); err == nil {
if tmp, ok := v.([]interface{}); reflect.TypeOf(v).Kind() == reflect.Slice && ok {
v = tmp[n]
}

View File

@ -36,8 +36,4 @@ func TestNew(t *testing.T) {
var s string
gr.Item("db.default.host", &s)
fmt.Println("item形式解释符串:", s)
// 根解释字符串
fmt.Println("根解释字符串", gr.String("db"))
fmt.Println("二级解释字符串", gr.String("db.default"))
}

13
yaml.go
View File

@ -16,21 +16,10 @@ type ConfigerChannelYAML struct {
func (conf *ConfigerChannelYAML) String(item string) string {
chunks := strings.SplitN(item, ".", 2)
var target interface{}
if len(chunks) > 1 {
target = recursiveParse(chunks[1], conf.tmp)
} else {
target = conf.tmp
}
target := recursiveParse(chunks[1], conf.tmp)
if str, ok := target.(string); ok {
return str
} else {
if out, err := yaml.Marshal(target); err == nil {
return bytes.NewBuffer(out).String()
}
}
return ""
}