goconf Go 的配置解析模块开源项目

我要开发同款
匿名用户2015年04月13日
18阅读
所属分类Google Go、程序开发、常用工具包
授权协议未知

作品详情

goconf是Go语言用来解析ini配置文件的模块,示例代码:

package main                                                                   import (                                                                           "fmt"                                                                          "github.com/Terry-Mao/goconf"                                              )                                                                              type TestConfig struct {    ID     int           `goconf:"core:id"`    Col    string        `goconf:"core:col"`    Ignore int           `goconf:"-"`    Arr    []string      `goconf:"core:arr:,"`    Test   time.Duration `goconf:"core:t_1:time"`    Buf    int           `goconf:"core:buf:memory"`    M      map[int]string`goconf:"coreⓂ,"`}func main() {                                                                      conf := goconf.New()                                                           if err := conf.Parse("./examples/conf_test.txt"); err != nil {                     panic(err)                                                                 }                                                                              core := conf.Get("core")                                                       if core == nil {                                                                   panic("no core section")                                                   }                                                                              id, err := core.Int("id")                                                      if err != nil {                                                                    panic(err)                                                                 }                                                                              fmt.Println(id)                                                                tf := &TestConfig{}    if err := conf.Unmarshall(tf); err != nil {        panic(err)    }    fmt.Println(tf.ID)}
声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论