-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
60 lines (49 loc) · 2.08 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
// The oplogd command is an agent listening on an UDP port for operations and exposing a
// HTTP SSE API.
//
// See README file for more information.
package main
import (
"flag"
"fmt"
"os"
log "github.com/Sirupsen/logrus"
"github.com/dailymotion/oplog"
)
var (
debug = flag.Bool("debug", false, "Show debug log messages.")
version = flag.Bool("version", false, "Show oplog version.")
listenAddr = flag.String("listen", ":8042", "The address to listen on. Same address is used for both SSE(HTTP) and UDP APIs.")
mongoURL = flag.String("mongo-url", os.Getenv("OPLOGD_MONGO_URL"), "MongoDB URL to connect to.")
cappedCollectionSize = flag.Int("capped-collection-size", 1048576, "Size of the created MongoDB capped collection size in bytes (default 1MB).")
maxQueuedEvents = flag.Int("max-queued-events", 100000, "Number of events to queue before starting throwing UDP messages.")
password = flag.String("password", os.Getenv("OPLOGD_PASSWORD"), "Password protecting the global SSE stream.")
ingestPassword = flag.String("ingest-password", os.Getenv("OPLOGD_INGEST_PASSWORD"), "Password protecting the HTTP ingest endpoint.")
objectURL = flag.String("object-url", os.Getenv("OPLOGD_OBJECT_URL"), "A URL template to reference objects. If this option is set, SSE events will have an \"ref\" field with the URL to the object. The URL should contain {{type}} and {{id}} variables (i.e.: http://api.mydomain.com/{{type}}/{{id}})")
)
// Test
func main() {
flag.Parse()
if *version {
fmt.Println(oplog.Version)
return
}
if *debug {
log.SetLevel(log.DebugLevel)
}
log.Infof("Starting oplog %s", oplog.Version)
ol, err := oplog.New(*mongoURL, *cappedCollectionSize)
if err != nil {
log.Fatal(err)
}
ol.ObjectURL = *objectURL
log.Infof("Listening on %s (UDP/TCP)", *listenAddr)
udpd := oplog.NewUDPDaemon(*listenAddr, ol)
go func() {
log.Fatal(udpd.Run(*maxQueuedEvents))
}()
ssed := oplog.NewSSEDaemon(*listenAddr, ol)
ssed.Password = *password
ssed.IngestPassword = *ingestPassword
log.Fatal(ssed.Run())
}