Skip to content

Commit 2644957

Browse files
authored
example changed
1 parent 5f3160b commit 2644957

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

example_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package oplog_test
2+
3+
import (
4+
"log"
5+
6+
"github.com/gnokoheat/oplog"
7+
)
8+
9+
func ExampleTail() {
10+
var o = &oplog.Options{
11+
// (e.g. mongodb://username:password@127.0.0.1:27017,127.0.0.1:27018/local?replicaSet=rs01&authSource=admin)
12+
Addrs: []string{"127.0.0.1:27017", "127.0.0.1:27018"}, // replicaset host and port
13+
Username: "username", // admin db username
14+
Password: "password", // admin db user password
15+
ReplicaSet: "rs01", // replicaset name
16+
DB: "myDB", // tailing target db
17+
Collection: "myCollection", // tailing target collection
18+
Events: []string{"insert", "update", "delete"}, // tailing target method
19+
}
20+
21+
l := make(chan *[]oplog.Log) // Oplog Channel
22+
e := make(chan error) // Error Channel
23+
24+
// Oplog tailing start !
25+
go o.Tail(l, e)
26+
27+
for {
28+
select {
29+
case err := <-e:
30+
log.Println("[Error] ", err)
31+
return
32+
case op := <-l:
33+
// input oplog handling code
34+
log.Println("[Result] ", op)
35+
break
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)