-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (70 loc) · 1.86 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"
"flag"
"fmt"
"net/http"
"time"
// _ "net/http/pprof"
"github.com/rexlx/scream/charter"
// "github.com/rexlx/scream/charter"
)
func main() {
flag.Parse()
cfg := &tls.Config{
MinVersion: tls.VersionTLS12, // Or tls.VersionTLS13 for stricter security
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
PreferServerCipherSuites: true,
CipherSuites: []uint16{
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
},
}
cert, err := tls.LoadX509KeyPair(*certFile, *keyFile)
if err != nil {
fmt.Println("error loading cert", err)
return
}
cfg.Certificates = []tls.Certificate{cert}
if *selfHostMicroService {
fmt.Println("starting charter", *chartServiceURL, *chartServicePort, *chartServiceLog)
charter, err := charter.NewServer(*chartServiceLog)
if err != nil {
fmt.Println("error starting charter", err)
return
}
chartServer := &http.Server{
Addr: *chartServicePort,
Handler: charter.Gateway,
ErrorLog: charter.Logger,
}
go func() {
err = chartServer.ListenAndServe()
if err != nil {
fmt.Println("error starting chart server", err)
}
}()
}
s := NewServer(*url, *firstUserMode, *chartServiceURL)
server := &http.Server{
Addr: *url,
Handler: s.Session.LoadAndSave(s.Gateway),
TLSConfig: cfg,
}
s.CleanUpTokens()
ticker := time.NewTicker(*updateFreq)
go func(t time.Duration) {
for range ticker.C {
s.UpdateGraphs(t)
}
}(*updateFreq)
s.Logger.Println("server started")
fmt.Println("server started", s.URL)
err = server.ListenAndServeTLS("", "")
// err = server.ListenAndServeTLS(*certFile, *keyFile)
if err != nil {
fmt.Println("error starting server", err)
}
}