Go 的配置解析模块 goconf

未知
Google Go
跨平台
2015-04-13
红薯

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)
}
加载中

评论(0)

暂无评论

暂无资讯

暂无问答

Go 语言项目

Indexes and search engines These sites provide indexes and search engines for Go packages: godoc.org gowalker gosearch Sourcegraph Contributing To edit this page you must be a c...

2014/01/03 21:49
773
0

没有更多内容

加载失败,请刷新页面

没有更多内容

返回顶部
顶部