summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/pelletier/go-toml/doc_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/pelletier/go-toml/doc_test.go')
-rw-r--r--vendor/github.com/pelletier/go-toml/doc_test.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/vendor/github.com/pelletier/go-toml/doc_test.go b/vendor/github.com/pelletier/go-toml/doc_test.go
index 31b4f40b5..9dd773899 100644
--- a/vendor/github.com/pelletier/go-toml/doc_test.go
+++ b/vendor/github.com/pelletier/go-toml/doc_test.go
@@ -6,7 +6,7 @@ import (
"fmt"
)
-func Example_comprehensiveExample() {
+func Example_tree() {
config, err := LoadFile("config.toml")
if err != nil {
@@ -20,10 +20,34 @@ func Example_comprehensiveExample() {
configTree := config.Get("postgres").(*Tree)
user = configTree.Get("user").(string)
password = configTree.Get("password").(string)
- fmt.Println("User is ", user, ". Password is ", password)
+ fmt.Println("User is", user, " and 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"))
}
}
+
+func Example_unmarshal() {
+ type Employer struct {
+ Name string
+ Phone string
+ }
+ type Person struct {
+ Name string
+ Age int64
+ Employer Employer
+ }
+
+ document := []byte(`
+ name = "John"
+ age = 30
+ [employer]
+ name = "Company Inc."
+ phone = "+1 234 567 89012"
+ `)
+
+ person := Person{}
+ Unmarshal(document, &person)
+ fmt.Println(person.Name, "is", person.Age, "and works at", person.Employer.Name)
+}