1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
package toml_test
import (
"bytes"
"encoding/json"
"fmt"
"github.com/komkom/toml"
)
func ExampleReader() {
doc := `
[some]
toml="doc"
[to.map]
"!"=true`
dec := json.NewDecoder(toml.New(bytes.NewBufferString(doc)))
st := struct {
Some struct {
Toml string `json:"toml"`
} `json:"some"`
To struct {
Map struct {
IsMarked bool `json:"!"`
}
} `json:"to"`
}{}
err := dec.Decode(&st)
if err != nil {
panic(err)
}
fmt.Printf("toml: %v", st.Some.Toml)
fmt.Printf(" is_marked: %v", st.To.Map.IsMarked)
// Output: toml: doc is_marked: true
}
|