Revised readme per peer-review

This commit is contained in:
eanderton
2014-10-01 18:38:03 -04:00
parent d9de45b5b5
commit 66e7f06e7d
2 changed files with 56 additions and 57 deletions
+31 -1
View File
@@ -2,7 +2,9 @@
package toml
import "fmt"
import (
"fmt"
)
func ExampleNodeFilterFn_filterExample() {
tree, _ := Load(`
@@ -49,3 +51,31 @@ func ExampleQuery_queryExample() {
fmt.Println(name)
}
}
func Example_comprehensiveExample() {
config, err := LoadFile("config.toml")
if err != nil {
fmt.Println("Error ", err.Error())
} else {
// retrieve data directly
user := config.Get("postgres.user").(string)
password := config.Get("postgres.password").(string)
// or using an intermediate object
configTree := config.Get("postgres").(*TomlTree)
user = configTree.Get("user").(string)
password = configTree.Get("password").(string)
fmt.Println("User is ", user, ". Password is ", password)
// show where elements are in the file
fmt.Println("User position: %v", configTree.GetPosition("user"))
fmt.Println("Password position: %v", configTree.GetPosition("password"))
// use a query to gather elements without walking the tree
results, _ := config.Query("$..[user,password]")
for ii, item := range results.Values() {
fmt.Println("Query result %d: %v", ii, item)
}
}
}