-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample_test.go
More file actions
54 lines (47 loc) · 1.12 KB
/
example_test.go
File metadata and controls
54 lines (47 loc) · 1.12 KB
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
52
53
54
package pickjson
import (
"fmt"
"strings"
)
const (
jsonExample = `{
"benchmark": "benchmark text 1",
"menu": {
"header": "SVG Viewer",
"image": {
"src": "Images/Sun.png",
"name": "sun1",
"hOffset": 250,
"vOffset": 250,
"alignment": "center",
"hidden": true
}
},
"benchmark": "benchmark text 2",
}`
)
// pick string
func ExamplePickString() {
benchmarks := PickString(strings.NewReader(jsonExample), "benchmark", 0)
fmt.Println(benchmarks)
// Output: [benchmark text 1 benchmark text 2]
}
// pick string just the 1st one
func ExamplePickStringLimit() {
benchmarks := PickString(strings.NewReader(jsonExample), "benchmark", 1)
fmt.Println(benchmarks)
// Output: [benchmark text 1]
}
// pick bool
func ExamplePickBool() {
hidden := PickBool(strings.NewReader(jsonExample), "hidden", 0)
fmt.Println(hidden)
// Output: [true]
}
// pick object
func ExamplePickObject() {
var img image
PickObject(strings.NewReader(jsonExample), "image", &img)
fmt.Println(img)
// Output: {Images/Sun.png sun1 250 250 center}
}