同步操作将从 无闻/goconfig 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
goconfig is a easy-use, comments-support configuration file parser for the Go Programming Language which provides a structure similar to what you would find on Microsoft Windows INI files.
The configuration file consists of sections, led by a "[section]" header and followed by "name:value" entries; "name=value" is also accepted. Note that leading whitespace is removed from values. The optional values can contain format strings which refer to other values in the same section, or values in a special DEFAULT section. Comments are indicated by ";" or "#"; comments may begin anywhere on a single line.
; Google
google=www.google.com
search: http://%(google)s
; Here are Comments
; Second line
[Demo]
# This symbol can also make this line to be comments
key1=Let's us GoConfig!!!
key2=test data
key3=this is based on key2:%(key2)s
[What's this?]
; Not Enough Comments!!
name=try one more value ^-^
[parent]
name=john
relation=father
sex=male
age=32
[parent.child]
age=3
[parent.child.child]
; Auto increment by setting key to "-"
[auto increment]
-:hello
-:go
-=config
c, err := LoadConfigFile("config.ini")
if err != nil {
t.Error(err)
}
// GetValue
value, _ := c.GetValue("Demo", "key1") // return "Let's use GoConfig!!!"
if value != "Let's us GoConfig!!!" {
t.Error("Error occurs when GetValue of key1")
}
// GetComments
comments := c.GetKeyComments("Demo", "key1") // return "# This symbol can also make this line to be comments"
if comments != "# This symbol can also make this line to be comments" {
t.Error("Error occurs when GetKeyComments")
}
// SetValue
c.SetValue("What's this?", "name", "Do it!") // Now name's value is "Do it!"
search, _ := c.GetValue(DEFAULT_SECTION, "search")
c.SetValue(DEFAULT_SECTION, "path", search)
key3, _ := c.GetValue("Demo", "key3")
c.SetValue("Demo", "key3", key3)
// You can even edit comments in your code
c.SetKeyComments("Demo", "key1", "")
c.SetKeyComments("Demo", "key2", "comments by code without symbol")
c.SetKeyComments("Demo", "key3", "# comments by code with symbol")
// Don't need that key any more? Pass empty string "" to remove! that's all!'
c.SetValue("What's this?", "name", "") // If your key was removed, its comments will be removed too!
c.SetValue("What's this?", "name_test", "added by test")
// Support for recursion sections.
age, _ := c.GetValue("parent.child", "age")
if age != "3" {
t.Errorf("Recursion section: should have %d but get %s.", 3, age) // 3, not 32.
}
name, _ := c.GetValue("parent.child", "name")
if name != "john" {
t.Errorf("Recursion section: should have %s but get %s.", "john", name) // "john", not empty.
}
name, _ = c.GetValue("parent.child.child", "name")
if name != "john" {
t.Errorf("Recursion section2: should have %s but get %s.", "john", name) // "john", not empty.
}
// GetSection and auto increment.
se, _ := c.GetSection("auto increment")
if len(se) != 3 {
t.Errorf("GetSection: should have %d of map elements but get %d.", 3,
len(se)) // 3
}
hello, _ := c.GetValue("auto increment", "#1")
if hello != "hello" {
t.Error("Error occurs when GetValue of auto increment: " + hello) // "hello", not empty.
}
// Finally, you need to save it
SaveConfigFile(c, "config_test.ini")
go get github.com/Unknwon/goconfig
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。