简单地读取不同环境的配置, 目前仅限于YAML
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
liangzy 8d7803d99d 1.二级节点直接解释字符串优化 1 year ago
conf 1.写文档 1 year ago
.gitignore new project 1 year ago
README.md 1.写文档 1 year ago
grconfig.go 1.二级节点直接解释字符串优化 1 year ago
grconfig_test.go 1.二级节点直接解释字符串优化 1 year ago
ini.go new project 1 year ago
json.go new project 1 year ago
xml.go new project 1 year ago
yaml.go 1.二级节点直接解释字符串优化 1 year ago

README.md

grconfig

使用方法直接看 grconfig_test.go

import "golib.gaore.com/GaoreGo/grconfig"
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)