-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathmain.go
59 lines (50 loc) · 1.27 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
package main
import (
"flag"
"github.com/juju/errors"
log "github.com/ngaut/logging"
"strconv"
"time"
)
type fnHttpCall func(objPtr interface{}, api string, method string, arg interface{}) error
type aliveCheckerFactory func(addr string, defaultTimeout time.Duration) AliveChecker
var (
apiServer = flag.String("codis-config", "localhost:18087", "api server address")
productName = flag.String("productName", "test", "product name, can be found in codis-proxy's config")
logLevel = flag.String("log-level", "info", "log level")
callHttp fnHttpCall = httpCall
acf aliveCheckerFactory = func(addr string, timeout time.Duration) AliveChecker {
return &redisChecker{
addr: addr,
defaultTimeout: timeout,
}
}
)
func genUrl(args ...interface{}) string {
url := "http://"
for _, v := range args {
switch v.(type) {
case string:
url += v.(string)
case int:
url += strconv.Itoa(v.(int))
default:
log.Errorf("unsupported type %T", v)
}
}
return url
}
func main() {
flag.Parse()
log.SetLevelByString(*logLevel)
for {
groups, err := GetServerGroups()
if err != nil {
log.Error(errors.ErrorStack(err))
return
}
CheckAliveAndPromote(groups)
CheckOfflineAndPromoteSlave(groups)
time.Sleep(3 * time.Second)
}
}