-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.go
83 lines (64 loc) · 1.81 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"sync"
"github.com/litl/shuttle/log"
)
var (
// Location of the default config.
// This will not be overwritten by shuttle.
defaultConfig string
// Location of the live config which is updated on every state change.
// The default config is loaded if this file does not exist.
stateConfig string
// Listen addressed for the http servers.
httpAddr string
httpsAddr string
// Listen address for the http server.
adminListenAddr string
// Debug logging
debug bool
// Redirect to HTTPS endpoint
httpsRedirect bool
// version flags
version bool
buildVersion string
// SSL Certificate directory
certDir string
)
func init() {
flag.StringVar(&httpAddr, "http", "", "http server address")
flag.StringVar(&httpsAddr, "https", "", "https server address")
flag.StringVar(&adminListenAddr, "admin", "127.0.0.1:9090", "admin http server address")
flag.StringVar(&defaultConfig, "config", "", "default config file")
flag.StringVar(&stateConfig, "state", "", "updated config which reflects the internal state")
flag.StringVar(&certDir, "certs", "./", "directory containing SSL Certficates and Keys")
flag.BoolVar(&debug, "debug", false, "verbose logging")
flag.BoolVar(&version, "v", false, "display version")
flag.BoolVar(&httpsRedirect, "https-redirect", false, "redirect all http vhost requests to https")
flag.BoolVar(&httpsRedirect, "sslOnly", false, "require https (deprecated)")
flag.Parse()
}
func main() {
if debug {
log.DefaultLogger.Level = log.DEBUG
}
if version {
println(buildVersion)
return
}
log.Printf("Starting shuttle %s", buildVersion)
loadConfig()
var wg sync.WaitGroup
wg.Add(1)
go startAdminHTTPServer(&wg)
if httpAddr != "" {
wg.Add(1)
go startHTTPServer(&wg)
}
if httpsAddr != "" {
wg.Add(1)
go startHTTPSServer(&wg)
}
wg.Wait()
}