Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Log ¶
type Log struct { Timestamp bson.MongoTimestamp `json:"ts" bson:"ts"` HistoryID int64 `json:"h" bson:"h"` MongoVersion int `json:"v" bson:"v"` Operation string `json:"op" bson:"op"` Namespace string `json:"ns" bson:"ns"` Doc map[string]interface{} `json:"o" bson:"o"` Update map[string]interface{} `json:"o2" bson:"o2"` InitialID interface{} `json:"initialId" bson:"initialId"` }
Log : Oplog document
type Options ¶
type Options struct { Addrs []string Username string Password string ReplicaSet string DB string Collection string Events []string }
Options : MongoDB connection information for oplog tailing
func (*Options) MgoConn ¶
func (o *Options) MgoConn(e chan error) (*mgo.Session, *mgo.Collection, *mgo.Collection)
MgoConn : MongoDB connect
func (*Options) MgoDatabaseConn ¶
func (*Options) Tail ¶
Tail : MongoDB oplog tailing start
Example ¶
package main import ( "log" "github.com/eduardoslopes/oplog" ) func main() { var o = &oplog.Options{ // (e.g. mongodb://username:password@127.0.0.1:27017,127.0.0.1:27018/local?replicaSet=rs01&authSource=admin) Addrs: []string{"127.0.0.1:27017", "127.0.0.1:27018"}, // replicaset host and port Username: "username", // admin db username Password: "password", // admin db user password ReplicaSet: "rs01", // replicaset name DB: "myDB", // tailing target db Collection: "myCollection", // tailing target collection Events: []string{"insert", "update", "delete"}, // tailing target method } l := make(chan []*oplog.Log) // Oplog Channel e := make(chan error) // Error Channel // Oplog tailing start ! go o.Tail(l, e) for { select { case err := <-e: log.Println("[Error] ", err) return case op := <-l: // input oplog handling code log.Println("[Result] ", op) break } } }
Output:
func (*Options) TailFromScratch ¶
Click to show internal directories.
Click to hide internal directories.