golang的一个扩展包,用以方便的解析配置文件,目前很好的支持:xml,json,yaml,toml;也简单的支持:ini,但不推荐使用。
一个简单例子:
{ "Port": 8080, "Instance": [ { "Name": "gitbook", "Path": "/gitbook", "Cmd": ["ls", "ll"], "User": "dingdayu" } ]}// 实例type Instance struct {Name stringPathstringCmd[]stringUserstring}// 配置type Config struct {Port intInstance []Instance}var conf Configerr := config.New("conf.json", &conf)if err != nil {fmt.Println(err.Error())}fmt.Println(conf)安装:
go get github.com/dingdayu/golangtools/configGitHub地址:https://github.com/dingdayu/golangtools/
评论