小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Go開源項(xiàng)目 - goconfig 使用方法

 java_laq小館 2013-10-12

Go開源項(xiàng)目 - goconfig 使用方法

2013-01-11 10:24 by Danny.tian, ... 閱讀, ... 評論, 收藏, 編輯

goconfig 是Revel用到的一個開源工具, 它實(shí)現(xiàn)了一個基礎(chǔ)的配置文件解析器語言, 它的結(jié)構(gòu)類似于微軟的Windows INI文件.

配置文件由幾部分組成, 由"[section]"做頭部緊接著"name:value"鍵值對, 也可以用"name=value". 注意空格將被從values中刪除. 在相同的section可選的value能包含涉及其他values格式化字符串, 或values在一個特殊的DEFAULT部分. 另外defaults可以在初始化和檢索時被提供. 注釋字符時 ";" 或 "#", 一個注釋可以在任何一行開始出, 包括在相同的行的參數(shù)后或section聲明.

例如:

[My Section]
foodir: %(dir)s/whatever
dir=foo

"*%(dir)s*"將被dir的值foo替換, 全部的引用將按需解釋.

功能和工作流是松散的基于python標(biāo)準(zhǔn)庫的configparser包.

安裝

go get github.com/kless/goconfig/config

 運(yùn)行測試

cd ${GOPATH//:*}/src/github.com/kless/goconfig/config && go test && cd -

操作指令

下面是一個簡單的配置文件:

[DEFAULT]
host: www.
protocol: http://
base-url: %(protocol)s%(host)s

[service-1]
url: %(base-url)s/some/path
delegation: on
maxclients: 200 # do not set this higher
comments: This is a multi-line
    entry   # And this is a comment

來讀一下這個配置文件:

c, _ := config.ReadDefault("config.cfg")

c.String("service-1", "url")
// result is string "http://www./some/path"

c.Int("service-1", "maxclients")
// result is int 200

c.Bool("service-1", "delegation")
// result is bool true

c.String("service-1", "comments")
// result is string "This is a multi-line\nentry"

注意: 支持展開變量(像這樣%(base-url)s), 它從保留的section名稱[DEFAULT]中讀取.

一個新的配置文件也能用代碼創(chuàng)建:

c := config.NewDefault()
c.AddSection("Section")
c.AddOption("Section", "option", "value")
c.WriteFile("config.cfg", 0644, "A header for this file")

創(chuàng)建的文件內(nèi)容如下:

# A header for this file

[Section]
option: value

注意section, options和vaules全部是大小寫敏感的.

 

至此結(jié)束.


來自:http://www.cnblogs.com/ztiandan/archive/2013/01/06/2848184.html

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多