File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments