23f644976a
Move all the query system to its own package. The reason is to avoid it to rely on unexported methods and structures, and move it out of the main package since this is really not a core feature. It is still tied to the toml.TomlTree and toml.Position structures for now. * Move query mechanism to its own subpackage * Rename QueryResult to Result to avoid stutter * Add query.CompileAndExecute Fixes #116
30 lines
764 B
Go
30 lines
764 B
Go
// code examples for godoc
|
|
|
|
package toml
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
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.Printf("User position: %v\n", configTree.GetPosition("user"))
|
|
fmt.Printf("Password position: %v\n", configTree.GetPosition("password"))
|
|
}
|
|
}
|