Skip to content

Commit

Permalink
Fix example code in README (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy authored and pelletier committed Sep 24, 2017
1 parent 1d6b12b commit 16398ba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import "github.com/pelletier/go-toml"
Read a TOML document:

```go
config, _ := toml.LoadString(`
config, _ := toml.Load(`
[postgres]
user = "pelletier"
password = "mypassword"`)
Expand All @@ -42,7 +42,7 @@ user := config.Get("postgres.user").(string)

// or using an intermediate object
postgresConfig := config.Get("postgres").(*toml.Tree)
password = postgresConfig.Get("password").(string)
password := postgresConfig.Get("password").(string)
```

Or use Unmarshal:
Expand All @@ -62,15 +62,16 @@ user = "pelletier"
password = "mypassword"`)

config := Config{}
Unmarshal(doc, &config)
toml.Unmarshal(doc, &config)
fmt.Println("user=", config.Postgres.User)
```

Or use a query:

```go
// 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() {
fmt.Println("Query result %d: %v", ii, item)
}
Expand Down

0 comments on commit 16398ba

Please sign in to comment.