2021-01-21 17:30:45 +08:00
|
|
|
# GoINI [![PkgGoDev](https://pkg.go.dev/badge/github.com/xiaoqidun/goini)](https://pkg.go.dev/github.com/xiaoqidun/goini)
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
简单易用的Golang INI配置解析库
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
# 安装方法
|
2024-06-12 13:41:33 +08:00
|
|
|
|
|
|
|
```shell
|
2019-10-25 18:44:15 +08:00
|
|
|
go get -u github.com/xiaoqidun/goini
|
2024-06-12 13:41:33 +08:00
|
|
|
```
|
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
# 读取配置
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
## 从文件读取配置
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
```go
|
2024-06-12 13:41:33 +08:00
|
|
|
// 初始GoINI对象
|
2019-10-25 18:44:15 +08:00
|
|
|
ini := goini.NewGoINI()
|
2024-06-12 13:41:33 +08:00
|
|
|
// 从文件获取配置
|
2019-10-25 18:44:15 +08:00
|
|
|
if err := ini.LoadFile("./config.ini"); err != nil {
|
2024-06-12 13:49:07 +08:00
|
|
|
log.Println(err)
|
|
|
|
return
|
2019-10-25 18:44:15 +08:00
|
|
|
}
|
|
|
|
```
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
## 从字符读取配置
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
```go
|
2024-06-12 13:41:33 +08:00
|
|
|
// 初始GoINI对象
|
2019-10-25 18:44:15 +08:00
|
|
|
ini := goini.NewGoINI()
|
2024-06-12 13:41:33 +08:00
|
|
|
// 从字符获取配置
|
2019-10-25 18:44:15 +08:00
|
|
|
ini.SetData([]byte(""))
|
|
|
|
```
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
# 注释方法
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
goini将;或#开头的行识别为注释信息
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
# 分区支持
|
2024-06-12 13:41:33 +08:00
|
|
|
|
2019-10-25 18:44:15 +08:00
|
|
|
goini将[](英文中括号)识别为分区
|