aboutsummaryrefslogtreecommitdiff
path: root/loader_test.go
blob: 3e1692292e7c04661cd81e57395292fbd1c6fb93 (plain) (blame)
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
43
44
45
46
47
48
49
50
51
package conf_test

import (
	"fmt"

	"go.neonxp.ru/conf"
	"go.neonxp.ru/conf/visitor"
)

func ExampleNew() {
	config := `
		key = "value";
		group "test" {
			key = 123;
		}
	`

	cfg := conf.New()

	if err := cfg.Load("example", []byte(config)); err != nil {
		panic(err)
	}

	pr := visitor.NewDefault()
	if err := cfg.Process(pr); err != nil {
		panic(err)
	}

	val1, err := pr.Get("key")
	if err != nil {
		panic(err)
	}
	val2, err := pr.Get("group.key")
	if err != nil {
		panic(err)
	}

	val3, err := pr.Get("group")
	if err != nil {
		panic(err)
	}

	fmt.Println("key =", val1.String())
	fmt.Println("group.key =", val2.String())
	fmt.Println("group args =", val3.String())

	// Output:
	// key = value
	// group.key = 123
	// group args = test
}