Fix example code in README (#187)
This commit is contained in:
committed by
Thomas Pelletier
parent
1d6b12b7cb
commit
16398bac15
@@ -33,7 +33,7 @@ import "github.com/pelletier/go-toml"
|
|||||||
Read a TOML document:
|
Read a TOML document:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
config, _ := toml.LoadString(`
|
config, _ := toml.Load(`
|
||||||
[postgres]
|
[postgres]
|
||||||
user = "pelletier"
|
user = "pelletier"
|
||||||
password = "mypassword"`)
|
password = "mypassword"`)
|
||||||
@@ -42,7 +42,7 @@ user := config.Get("postgres.user").(string)
|
|||||||
|
|
||||||
// or using an intermediate object
|
// or using an intermediate object
|
||||||
postgresConfig := config.Get("postgres").(*toml.Tree)
|
postgresConfig := config.Get("postgres").(*toml.Tree)
|
||||||
password = postgresConfig.Get("password").(string)
|
password := postgresConfig.Get("password").(string)
|
||||||
```
|
```
|
||||||
|
|
||||||
Or use Unmarshal:
|
Or use Unmarshal:
|
||||||
@@ -62,7 +62,7 @@ user = "pelletier"
|
|||||||
password = "mypassword"`)
|
password = "mypassword"`)
|
||||||
|
|
||||||
config := Config{}
|
config := Config{}
|
||||||
Unmarshal(doc, &config)
|
toml.Unmarshal(doc, &config)
|
||||||
fmt.Println("user=", config.Postgres.User)
|
fmt.Println("user=", config.Postgres.User)
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -70,7 +70,8 @@ Or use a query:
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
// use a query to gather elements without walking the tree
|
// use a query to gather elements without walking the tree
|
||||||
results, _ := config.Query("$..[user,password]")
|
q, _ := query.Compile("$..[user,password]")
|
||||||
|
results := q.Execute(config)
|
||||||
for ii, item := range results.Values() {
|
for ii, item := range results.Values() {
|
||||||
fmt.Println("Query result %d: %v", ii, item)
|
fmt.Println("Query result %d: %v", ii, item)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user