-
Notifications
You must be signed in to change notification settings - Fork 3
/
example_test.go
48 lines (42 loc) · 969 Bytes
/
example_test.go
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
package oplogc_test
import (
"log"
"github.com/dailymotion/oplogc"
)
func Example() {
myOplogURL := "http://oplog.mydomain.com"
c := oplogc.Subscribe(myOplogURL, oplogc.Options{})
ops, errs, done := c.Start()
for {
select {
case op := <-ops:
// Got the next operation
switch op.Event {
case "reset":
// reset the data store
case "live":
// put the service back in production
default:
// Do something with the operation
//url := fmt.Sprintf("http://api.domain.com/%s/%s", op.Data.Type, op.Data.ID)
//data := MyAPIGetter(url)
//MyDataSyncer(data)
}
// Ack the fact you handled the operation
op.Done()
case err := <-errs:
switch err {
case oplogc.ErrAccessDenied, oplogc.ErrWritingState:
c.Stop()
log.Fatal(err)
case oplogc.ErrResumeFailed:
log.Print("Resume failed, forcing full replication")
c.SetLastID("0")
default:
log.Print(err)
}
case <-done:
return
}
}
}