Skip to content

Commit 3a70d4d

Browse files
authored
shadow: update shadow example (#129)
* Update example to use nested shadow document * Show shadow delta on example
1 parent e673833 commit 3a70d4d

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

examples/shadow/main.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,45 @@ func main() {
8181
s.OnError(func(err error) {
8282
fmt.Printf("async error: %v\n", err)
8383
})
84+
s.OnDelta(func(delta map[string]interface{}) {
85+
fmt.Printf("delta: %+v\n", delta)
86+
})
8487
cli.Handle(s)
8588

8689
fmt.Print("> update desire\n")
87-
doc, err := s.Desire(ctx, sampleState{Value: 1})
90+
doc, err := s.Desire(ctx, sampleState{Value: 1, Struct: sampleStruct{Values: []int{1, 2}}})
8891
if err != nil {
8992
panic(err)
9093
}
91-
fmt.Printf("document: %v\n", doc)
94+
fmt.Printf("document: %+v\n", doc)
9295

9396
fmt.Print("> update report\n")
94-
doc, err = s.Report(ctx, sampleState{Value: 2})
97+
doc, err = s.Report(ctx, sampleState{Value: 2, Struct: sampleStruct{Values: []int{1, 2}}})
9598
if err != nil {
9699
panic(err)
97100
}
98-
fmt.Printf("document: %v\n", doc)
101+
fmt.Printf("document: %+v\n", doc)
99102

100103
fmt.Print("> get document\n")
101104
doc, err = s.Get(ctx)
102105
if err != nil {
103106
panic(err)
104107
}
105-
fmt.Printf("document: %v\n", doc)
108+
fmt.Printf("document: %+v\n", doc)
106109

107110
fmt.Print("> delete\n")
108111
err = s.Delete(ctx)
109112
if err != nil {
110113
panic(err)
111114
}
112-
fmt.Printf("document: %v\n", s.Document())
115+
fmt.Printf("document: %+v\n", s.Document())
116+
}
117+
118+
type sampleStruct struct {
119+
Values []int
113120
}
114121

115122
type sampleState struct {
116123
Value int
117-
Struct struct {
118-
NestedValue int
119-
}
124+
Struct sampleStruct
120125
}

0 commit comments

Comments
 (0)