grconfig/grconfig_test.go
liangzy 8d7803d99d 1.二级节点直接解释字符串优化
2.根节点不能解释成字符串的bug Fixed
2020-08-10 09:59:29 +08:00

44 lines
882 B
Go

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)
// 根解释字符串
fmt.Println("根解释字符串", gr.String("db"))
fmt.Println("二级解释字符串", gr.String("db.default"))
}