forked from fabiolb/fabio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (58 loc) · 1.39 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 (
"flag"
"fmt"
"log"
"net"
"net/http"
"github.com/eBay/fabio/config"
"github.com/eBay/fabio/proxy"
"github.com/eBay/fabio/route"
"github.com/eBay/fabio/ui"
)
var version = "1.0.5"
func main() {
var filename string
var v bool
flag.StringVar(&filename, "cfg", "", "path to config file")
flag.BoolVar(&v, "v", false, "show version")
flag.Parse()
if v {
fmt.Println(version)
return
}
log.Printf("[INFO] Version %s starting", version)
cfg := config.DefaultConfig
if filename != "" {
cfg = loadConfig(filename)
}
initConsul(cfg)
initMetrics(cfg)
initRuntime(cfg)
initRoutes(cfg)
startUI(cfg)
startListeners(cfg.Listen, cfg.Proxy.ShutdownWait, newProxy(cfg))
}
func newProxy(cfg *config.Config) *proxy.Proxy {
if err := route.SetPickerStrategy(cfg.Proxy.Strategy); err != nil {
log.Fatal("[FATAL] ", err)
}
log.Printf("[INFO] Using routing strategy %q", cfg.Proxy.Strategy)
tr := &http.Transport{
ResponseHeaderTimeout: cfg.Proxy.ResponseHeaderTimeout,
MaxIdleConnsPerHost: cfg.Proxy.MaxConn,
Dial: (&net.Dialer{
Timeout: cfg.Proxy.DialTimeout,
KeepAlive: cfg.Proxy.KeepAliveTimeout,
}).Dial,
}
return proxy.New(tr, cfg.Proxy)
}
func startUI(cfg *config.Config) {
log.Printf("[INFO] UI listening on %q", cfg.UI.Addr)
go func() {
if err := ui.Start(cfg.UI.Addr, cfg.Consul.KVPath); err != nil {
log.Fatal("[FATAL] ui: ", err)
}
}()
}