Skip to content

Commit

Permalink
update some info
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Aug 11, 2019
1 parent d65f590 commit 2cffadb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 16 deletions.
22 changes: 11 additions & 11 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import (

// go run ./examples/demo.go
func main() {
// config, err := ini.LoadFiles("testdata/tesdt.ini")
// err := ini.LoadFiles("testdata/tesdt.ini")
// LoadExists 将忽略不存在的文件
err := ini.LoadExists("testdata/test.ini", "not-exist.ini")
if err != nil {
Expand All @@ -76,7 +76,7 @@ age = 100
newK = newVal
some = change val
`)
// fmt.Printf("%v\n", config.Data())
// fmt.Printf("%v\n", ini.Data())
}
```

Expand All @@ -85,59 +85,59 @@ some = change val
- 获取整型

```go
age := config.Int("age")
age := ini.Int("age")
fmt.Print(age) // 100
```

- 获取布尔值

```go
val := config.Bool("debug")
val := ini.Bool("debug")
fmt.Print(val) // true
```

- 获取字符串

```go
name := config.String("name")
name := ini.String("name")
fmt.Print(name) // inhere
```

- 获取section数据(string map)

```go
val := config.StringMap("sec1")
val := ini.StringMap("sec1")
fmt.Println(val)
// map[string]string{"key":"val0", "some":"change val", "stuff":"things", "newK":"newVal"}
```

- 获取的值是环境变量

```go
value := config.String("shell")
value := ini.String("shell")
fmt.Printf("%q", value) // "/bin/zsh"
```

- 通过key path来直接获取子级值

```go
value := config.String("sec1.key")
value := ini.String("sec1.key")
fmt.Print(value) // val0
```

- 支持变量参考

```go
value := config.String("sec1.varRef")
value := ini.String("sec1.varRef")
fmt.Printf("%q", value) // "val in default section"
```

- 设置新的值

```go
// set value
config.Set("name", "new name")
name = config.String("name")
ini.Set("name", "new name")
name = ini.String("name")
fmt.Printf("%q", value) // "new name"
```

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@ module github.com/gookit/ini/v2

require (
github.com/gookit/goutil v0.1.7
github.com/pkg/errors v0.8.1
github.com/stretchr/testify v1.3.0
)
12 changes: 11 additions & 1 deletion ini.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ func (c *Ini) loadFile(file string, loadExist bool) (err error) {

return
}
//noinspection GoUnhandledErrorResult
defer fd.Close()

// read file content
Expand All @@ -297,6 +298,10 @@ func (c *Ini) loadFile(file string, loadExist bool) (err error) {
return
}

/*************************************************************
* helper methods
*************************************************************/

// HasKey check key exists
func HasKey(key string) bool { return dc.HasKey(key) }

Expand Down Expand Up @@ -358,6 +363,11 @@ func (c *Ini) Data() map[string]Section {
return c.data
}

// MapTo struct pointer WIP
func (c *Ini) MapTo(ptr interface{}) error {
return nil
}

// Error get
func Error() error { return dc.Error() }

Expand All @@ -372,7 +382,7 @@ func (c *Ini) addErrorf(format string, a ...interface{}) {
}

/*************************************************************
* helper methods
* internal helper methods
*************************************************************/

func (c *Ini) splitSectionAndKey(key string) (string, string) {
Expand Down
2 changes: 1 addition & 1 deletion parser/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ini parser
# INI Parser

This is a parser for parse INI format content to golang data

Expand Down
3 changes: 1 addition & 2 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ package parser
import (
"bufio"
"bytes"
"errors"
"fmt"
"regexp"
"strings"

"github.com/pkg/errors"
)

// errSyntax is returned when there is a syntax error in an INI file.
Expand Down

0 comments on commit 2cffadb

Please sign in to comment.