• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

testdata/H08-Sep-2020-135109

.gitignoreH A D08-Sep-202021 33

LICENSEH A D08-Sep-202010 KiB191155

README.mdH A D08-Sep-20203.3 KiB6945

README_ZH.mdH A D08-Sep-20202.7 KiB6540

conf.goH A D08-Sep-202014.7 KiB556358

goconfig_test.goH A D08-Sep-202011.1 KiB399318

read.goH A D08-Sep-20207.5 KiB295239

util.goH A D08-Sep-2020796 268

write.goH A D08-Sep-20202.9 KiB11884

README.md

1goconfig [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/goconfig)
2========
3
4[中文文档](README_ZH.md)
5
6**IMPORTANT**
7
8- This library is under bug fix only mode, which means no more features will be added.
9- I'm continuing working on better Go code with a different library: [ini](https://github.com/go-ini/ini).
10
11## About
12
13Package 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.
14
15The configuration file consists of sections, led by a `[section]` header and followed by `name:value` or `name=value` entries. 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.
16
17## Features
18
19- It simplified operation processes, easy to use and undersatnd; therefore, there are less chances to have errors.
20- It uses exactly the same way to access a configuration file as you use Windows APIs, so you don't need to change your code style.
21- It supports read recursion sections.
22- It supports auto increment of key.
23- It supports **READ** and **WRITE** configuration file with comments each section or key which all the other parsers don't support!!!!!!!
24- It supports get value through type bool, float64, int, int64 and string, methods that start with "Must" means ignore errors and get zero-value if error occurs, or you can specify a default value.
25- It's able to load multiple files to overwrite key values.
26
27## Installation
28
29	go get github.com/unknwon/goconfig
30
31## API Documentation
32
33[Go Walker](http://gowalker.org/github.com/unknwon/goconfig).
34
35## Example
36
37Please see [conf.ini](testdata/conf.ini) as an example.
38
39### Usage
40
41- Function `LoadConfigFile` load file(s) depends on your situation, and return a variable with type `ConfigFile`.
42- `GetValue` gives basic functionality of getting a value of given section and key.
43- Methods like `Bool`, `Int`, `Int64` return corresponding type of values.
44- Methods start with `Must` return corresponding type of values and returns zero-value of given type if something goes wrong.
45- `SetValue` sets value to given section and key, and inserts somewhere if it does not exist.
46- `DeleteKey` deletes by given section and key.
47- Finally, `SaveConfigFile` saves your configuration to local file system.
48- Use method `Reload` in case someone else modified your file(s).
49- Methods contains `Comment` help you manipulate comments.
50- `LoadFromReader` allows loading data without an intermediate file.
51- `SaveConfigData` added, which writes configuration to an arbitrary writer.
52- `ReloadData` allows to reload data from memory.
53
54Note that you cannot mix in-memory configuration with on-disk configuration.
55
56## More Information
57
58- All characters are CASE SENSITIVE, BE CAREFUL!
59
60## Credits
61
62- [goconf](http://code.google.com/p/goconf/)
63- [robfig/config](https://github.com/robfig/config)
64- [Delete an item from a slice](https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/lYz8ftASMQ0)
65
66## License
67
68This project is under Apache v2 License. See the [LICENSE](LICENSE) file for the full license text.
69

README_ZH.md

1goconfig [![Build Status](https://drone.io/github.com/Unknwon/goconfig/status.png)](https://drone.io/github.com/Unknwon/goconfig/latest) [![Go Walker](http://gowalker.org/api/v1/badge)](http://gowalker.org/github.com/Unknwon/goconfig)
2========
3
4本库已被 [《Go名库讲解》](https://github.com/Unknwon/go-rock-libraries-showcases/tree/master/lectures/01-goconfig) 收录讲解,欢迎前往学习如何使用!
5
6编码规范:基于 [Go 编码规范](https://github.com/Unknwon/go-code-convention)
7
8## 关于
9
10包 goconfig 是一个易于使用,支持注释的 Go 语言配置文件解析器,该文件的书写格式和 Windows 下的 INI 文件一样。
11
12配置文件由形为 `[section]` 的节构成,内部使用 `name:value` 或 `name=value` 这样的键值对;每行开头和尾部的空白符号都将被忽略;如果未指定任何节,则会默认放入名为 `DEFAULT` 的节当中;可以使用 “;” 或 “#” 来作为注释的开头,并可以放置于任意的单独一行中。
13
14## 特性
15
16- 简化流程,易于理解,更少出错。
17- 提供与 Windows API 一模一样的操作方式。
18- 支持读取递归节。
19- 支持自增键名。
20- 支持对注释的 **读** 和 **写** 操作,其它所有解析器都不支持!!!!
21- 可以直接返回 bool, float64, int, int64 和 string 类型的值,如果使用 “Must” 开头的方法,则一定会返回这个类型的一个值而不返回错误,如果错误发生则会返回零值。
22- 支持加载多个文件来重写值。
23
24## 安装
25
26	go get github.com/Unknwon/goconfig
27
2829
30	gopm get github.com/Unknwon/goconfig
31
32
33## API 文档
34
35[Go Walker](http://gowalker.org/github.com/Unknwon/goconfig).
36
37## 示例
38
39请查看 [conf.ini](testdata/conf.ini) 文件作为使用示例。
40
41### 用例
42
43- 函数 `LoadConfigFile` 加载一个或多个文件,然后返回一个类型为 `ConfigFile` 的变量。
44- `GetValue` 可以简单的获取某个值。
45- 像 `Bool`、`Int`、`Int64` 这样的方法会直接返回指定类型的值。
46- 以 `Must` 开头的方法不会返回错误,但当错误发生时会返回零值。
47- `SetValue` 可以设置某个值。
48- `DeleteKey` 可以删除某个键。
49- 最后,`SaveConfigFile` 可以保持您的配置到本地文件系统。
50- 使用方法 `Reload` 可以重载您的配置文件。
51
52## 更多信息
53
54- 所有字符都是大小写敏感的!
55
56## 参考信息
57
58- [goconf](http://code.google.com/p/goconf/)
59- [robfig/config](https://github.com/robfig/config)
60- [Delete an item from a slice](https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/lYz8ftASMQ0)
61
62## 授权许可
63
64本项目采用 Apache v2 开源授权许可证,完整的授权说明已放置在 [LICENSE](LICENSE) 文件中。
65