-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
87 lines (72 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
84
85
86
87
package main
import (
"crypto/tls"
"net"
"net/http"
"os"
"github.com/gomicro/avenues/config"
log "github.com/gomicro/ledger"
)
var (
conf *config.File
version string
)
func configure() {
if version == "" {
version = "dev-local"
}
log.Infof("Avenues %v", version)
c, err := config.ParseFromFile()
if err != nil {
log.Fatalf("Failed to read config file: %v", err.Error())
os.Exit(1)
}
conf = c
log.Debug("Config file parsed")
log.Debug("Configuration complete")
}
func main() {
configure()
log.Infof("Listening on %v:%v", "0.0.0.0", "4567")
http.Handle("/", conf)
if conf.Key != "" && conf.Cert != "" {
log.Info("Serving with SSL")
cert, err := tls.X509KeyPair([]byte(conf.Cert), []byte(conf.Key))
if err != nil {
log.Fatalf("failed to create ssl cert/key pair: %v", err.Error())
os.Exit(1)
}
cfg := &tls.Config{
MinVersion: tls.VersionTLS12,
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
},
Certificates: []tls.Certificate{cert},
}
srv := &http.Server{
Addr: net.JoinHostPort("0.0.0.0", "4567"),
TLSConfig: cfg,
}
err = srv.ListenAndServeTLS("", "")
if err != nil {
log.Fatalf("something went horribly wrong: %v", err.Error())
os.Exit(1)
}
} else {
log.Info("Serving without SSL")
err := http.ListenAndServe("0.0.0.0:4567", nil)
if err != nil {
log.Fatalf("something went horribly wrong: %v", err.Error())
os.Exit(1)
}
}
}