File tree Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Expand file tree Collapse file tree 1 file changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -23,23 +23,44 @@ import (
23
23
func ExampleRuntime_Parse () {
24
24
const config = `
25
25
msg: "Hello \(place)!"
26
- place: "world"
26
+ place: string | * "world"
27
27
`
28
28
29
29
var r cue.Runtime
30
30
31
- instance , err := r .Parse ("test" , config )
31
+ instance , err := r .Compile ("test" , config )
32
32
if err != nil {
33
33
// handle error
34
34
}
35
35
36
- str , err := instance .Lookup ("msg" ).String ()
37
- if err != nil {
38
- // handle error
39
- }
36
+ str , _ := instance .Lookup ("msg" ).String ()
37
+ fmt .Println (str )
40
38
39
+ instance , _ = instance .Fill ("you" , "place" )
40
+ str , _ = instance .Lookup ("msg" ).String ()
41
41
fmt .Println (str )
42
42
43
43
// Output:
44
44
// Hello world!
45
+ // Hello you!
46
+ }
47
+
48
+ func ExampleValue_Decode () {
49
+ type ab struct { A , B int }
50
+
51
+ var x ab
52
+
53
+ var r cue.Runtime
54
+
55
+ i , _ := r .Compile ("test" , `{A: 2, B: 4}` )
56
+ _ = i .Value ().Decode (& x )
57
+ fmt .Println (x )
58
+
59
+ i , _ = r .Compile ("test" , `{B: "foo"}` )
60
+ err := i .Value ().Decode (& x )
61
+ fmt .Println (err )
62
+
63
+ // Output:
64
+ // {2 4}
65
+ // json: cannot unmarshal string into Go struct field ab.B of type int
45
66
}
You can’t perform that action at this time.
0 commit comments