mirror of
https://github.com/xiaoqidun/goini.git
synced 2024-11-23 23:16:46 +08:00
Compare commits
2 Commits
898da94c95
...
0edc5682de
Author | SHA1 | Date | |
---|---|---|---|
0edc5682de | |||
9f5b09376b |
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
.idea/
|
||||
.vscode/
|
||||
.devcontainer/
|
||||
|
22
README.md
22
README.md
@ -1,26 +1,40 @@
|
||||
# GoINI [![PkgGoDev](https://pkg.go.dev/badge/github.com/xiaoqidun/goini)](https://pkg.go.dev/github.com/xiaoqidun/goini)
|
||||
|
||||
简单易用的Golang INI配置解析库
|
||||
|
||||
# 安装方法
|
||||
|
||||
```shell
|
||||
go get -u github.com/xiaoqidun/goini
|
||||
```
|
||||
|
||||
# 读取配置
|
||||
|
||||
## 从文件读取配置
|
||||
|
||||
```go
|
||||
//初始GoINI对象
|
||||
// 初始GoINI对象
|
||||
ini := goini.NewGoINI()
|
||||
//从文件获取配置
|
||||
// 从文件获取配置
|
||||
if err := ini.LoadFile("./config.ini"); err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
```
|
||||
|
||||
## 从字符读取配置
|
||||
|
||||
```go
|
||||
//初始GoINI对象
|
||||
// 初始GoINI对象
|
||||
ini := goini.NewGoINI()
|
||||
//从字符获取配置
|
||||
// 从字符获取配置
|
||||
ini.SetData([]byte(""))
|
||||
```
|
||||
|
||||
# 注释方法
|
||||
|
||||
goini将;或#开头的行识别为注释信息
|
||||
|
||||
# 分区支持
|
||||
|
||||
goini将[](英文中括号)识别为分区
|
||||
|
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
||||
module github.com/xiaoqidun/goini
|
||||
|
||||
go 1.13
|
||||
go 1.20
|
||||
|
4
goini.go
4
goini.go
@ -3,7 +3,7 @@ package goini
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@ -135,7 +135,7 @@ func (ini *GoINI) SetData(fileData []byte) {
|
||||
|
||||
// LoadFile 从文件读取配置并解析
|
||||
func (ini *GoINI) LoadFile(fileName string) error {
|
||||
b, err := ioutil.ReadFile(fileName)
|
||||
b, err := os.ReadFile(fileName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user