-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (53 loc) · 1.36 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
62
63
64
65
66
67
68
package main
import (
"errors"
"flag"
"fmt"
"github.com/garyburd/redigo/redis"
"gopkg.in/gilmour-libs/gilmour-e-go.v0/backends"
"os"
)
const BLANK = ""
const GilmourHealthKey = "gilmour.known_host.health"
func newRedisPool(host string, port int) *redis.Pool {
return backends.GetPool(fmt.Sprintf("%v:%v", host, port))
}
func removeKey(pool *redis.Pool, ident string) (int, error) {
if ident == BLANK {
err := errors.New("Identifier to remove cannot be blank")
return 0, err
}
conn := pool.Get()
defer conn.Close()
return redis.Int(conn.Do("HDEL", GilmourHealthKey, ident))
}
func makeIdent(ident *string) {
flag.StringVar(ident, "ident", "", "key to cleanup")
}
func makeRedisConf(host *string, port *int) {
flag.StringVar(host, "host", "127.0.0.1", "Redis host to connect to")
flag.IntVar(port, "port", 6379, "Redis port")
}
func main() {
var ident string
var redis_host string
var redis_port int
makeIdent(&ident)
makeRedisConf(&redis_host, &redis_port)
flag.Parse()
pool := newRedisPool(redis_host, redis_port)
n, err := removeKey(pool, ident)
var status int
var message string
if err != nil {
message = err.Error()
status = 2
} else if n > 0 {
message = fmt.Sprintf("Host %v has been unregistered.", ident)
} else {
status = 1
message = fmt.Sprintf("Host %v could not be found", ident)
}
fmt.Println(message)
os.Exit(status)
}