package grconfig import ( "fmt" "testing" ) func TestNew(t *testing.T) { type Dsn struct { User string `yaml:"user"` Pass string `yaml:"pass"` Host string `yaml:"host"` Port int `yaml:"port"` Name string `yaml:"name"` Driver string `yaml:"driver"` Prefix string `yaml:"prefix"` } var items = make(map[string]*Dsn) // 一级 gr := New("conf/") fmt.Println(gr.Item("db", &items)) fmt.Printf("%+v\n", items["default"]) // 二级 a := new(Dsn) gr.Item("db.default", &a) fmt.Printf("%+v\n", a) // 解释字符串 fmt.Println("直接解释字符串", gr.String("db.default.host")) // item形式解释符串 var s string gr.Item("db.default.host", &s) fmt.Println("item形式解释符串:", s) }