-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (63 loc) · 1.51 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
package main
import (
"log"
"net/http"
"os"
"github.com/docker/docker/client"
"github.com/gorilla/mux"
"github.com/hashicorp/logutils"
"github.com/kelseyhightower/envconfig"
)
var (
appVersion = "unset"
port = ":8080"
)
type Port struct {
PublicPort uint16
PrivatePort uint16
Name string
Path string
}
type Container struct {
Ports []*Port
Name string
Image string
}
func main() {
filter := &logutils.LevelFilter{
Levels: []logutils.LogLevel{"INFO", "ERROR", "FATAL"},
MinLevel: logutils.LogLevel("INFO"),
Writer: os.Stderr,
}
log.SetOutput(filter)
log.SetFlags(log.LstdFlags | log.Lshortfile)
c := &Config{}
err := envconfig.Process("", c)
if err != nil {
log.Fatalf("[FATAL] failed to parse env vars: %s", err)
}
cl, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
log.Fatalf("[FATAL] %s", err)
}
app := App{
Router: mux.NewRouter(),
Config: c,
DockerClient: &Client{cl},
Version: appVersion,
}
app.routes()
log.Printf("[INFO] using receptionist label: %v", c.Label)
log.Printf("[INFO] listening on %s", port)
if c.TLSCertFile == "" || c.TLSKeyFile == "" {
log.Printf("[INFO] running insecure")
if err := http.ListenAndServe(port, app.Router); err != nil {
log.Fatalf("[FATAL] %s", err)
}
} else {
log.Printf("[INFO] running with tls")
if err = http.ListenAndServeTLS(port, c.TLSCertFile, c.TLSKeyFile, app.Router); err != nil {
log.Fatalf("[FATAL] %s", err)
}
}
}