grconfig/README.md

39 lines
776 B
Markdown
Raw Normal View History

2020-04-01 10:50:00 +08:00
# grconfig
使用方法直接看 `grconfig_test.go`
```go
import "golib.gaore.com/GaoreGo/grconfig"
```
```go
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)
```