-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
61 lines (52 loc) · 1.55 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
61
package main
import (
"flag"
"fmt"
"go.uber.org/zap"
"os"
)
var (
redisSentinelAddress = flag.String("sentinel-address", "", "the address of the Sentinel master")
redisSentinelMaster = flag.String("sentinel-master", "mymaster", "the name of the Sentinel master")
bind = flag.String("bind", "127.0.0.1:26380", "the address to bind to proxy connections to the active Sentinel")
timeout = flag.Int("connect-timeout", 1, "seconds before a connection to a master times out")
logger *zap.Logger
)
func main() {
flag.Parse()
initLogger, err := zap.NewProduction()
if err != nil {
_, _ = fmt.Fprintf(os.Stderr, "unable to initialize logger: %v", err)
os.Exit(1)
return
}
logger = initLogger
if *redisSentinelAddress == "" {
logger.Error("A Redis Sentinel address is required.")
os.Exit(1)
return
}
logger.Info("connecting to redis sentinel", zap.String("sentinel-address", *redisSentinelAddress))
monitor, err := NewRedisSentinelMonitor(*redisSentinelAddress, *redisSentinelMaster)
if err != nil {
logger.Info("unable to connect to redis sentinel",
zap.String("sentinel-address", *redisSentinelAddress),
zap.Error(err))
os.Exit(1)
return
}
server, err := NewSerpentinisedServer(*bind, monitor)
if err != nil {
logger.Info("unable to bind to address",
zap.String("address", *bind),
zap.Error(err))
os.Exit(1)
return
}
go monitor.monitorSentinelChanges()
if err := server.Listen(); err != nil {
logger.Info("error whilst listening for connections", zap.Error(err))
os.Exit(1)
return
}
}