-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
63 lines (52 loc) · 1.33 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
package main
import (
"flag"
log "github.com/sirupsen/logrus"
"github.com/aestek/haproxy-connect/haproxy/haproxyconfig"
"github.com/aestek/haproxy-connect/lib"
"github.com/hashicorp/consul/api"
"github.com/aestek/haproxy-connect/consul"
)
func main() {
log.SetLevel(log.TraceLevel)
consulAddr := flag.String("http-addr", "127.0.0.1:8500", "Consul agent address")
service := flag.String("sidecar-for", "", "The consul service to proxy")
haproxy := flag.String("haproxy", "haproxy", "Haproxy binary path")
haproxyCfgBasePath := flag.String("haproxy-cfg-base-path", "/tmp", "Haproxy binary path")
token := flag.String("token", "", "Consul ACL token")
flag.Parse()
sd := lib.NewShutdown()
consulConfig := &api.Config{
Address: *consulAddr,
}
if token != nil {
consulConfig.Token = *token
}
consulClient, err := api.NewClient(consulConfig)
if err != nil {
}
watcher := consul.New(*service, consulClient)
go func() {
if err := watcher.Run(); err != nil {
log.Error(err)
sd.Shutdown()
}
}()
opts := haproxyconfig.Options{
Bin: *haproxy,
ConfigBaseDir: *haproxyCfgBasePath,
}
if haproxy != nil {
opts.Bin = *haproxy
}
hap := haproxyconfig.New(watcher.C, opts)
sd.Add(1)
go func() {
defer sd.Done()
if err := hap.Run(sd); err != nil {
log.Error(err)
sd.Shutdown()
}
}()
sd.Wait()
}