-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (57 loc) · 1.64 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
package main
import (
"log"
prom "github.com/flf2ko/fasthttp-prometheus"
"github.com/valyala/fasthttp"
"github.com/cash-track/gateway/captcha"
"github.com/cash-track/gateway/config"
"github.com/cash-track/gateway/headers"
"github.com/cash-track/gateway/http/retryhttp"
"github.com/cash-track/gateway/logger"
"github.com/cash-track/gateway/router"
apiHandler "github.com/cash-track/gateway/router/api"
apiService "github.com/cash-track/gateway/service/api"
)
const (
readBufferSize = 1024 * 8
writeBufferSize = 1024 * 8
)
func main() {
config.Global.Load()
r := router.New(
apiHandler.NewHttp(
config.Global,
apiService.NewHttp(retryhttp.NewFastHttpRetryClient(), config.Global),
captcha.NewGoogleReCaptchaProvider(retryhttp.NewFastHttpRetryClient(), config.Global),
),
)
h := prom.NewPrometheus("http").WrapHandler(r.Router)
h = headers.Handler(h)
h = headers.CorsHandler(h)
h = logger.DebugHandler(h)
if config.Global.Compress {
h = fasthttp.CompressHandler(h)
}
s := &fasthttp.Server{
Handler: h,
ReadBufferSize: readBufferSize,
WriteBufferSize: writeBufferSize,
}
if config.Global.HttpsEnabled {
startTls(s)
} else {
start(s)
}
}
func start(s *fasthttp.Server) {
log.Printf("Listening on HTTP %s", config.Global.Address)
if err := s.ListenAndServe(config.Global.Address); err != nil {
log.Fatalf("Error in HTTP server: %v", err)
}
}
func startTls(s *fasthttp.Server) {
log.Printf("Listening on HTTPS %s", config.Global.Address)
if err := s.ListenAndServeTLS(config.Global.Address, config.Global.HttpsCrt, config.Global.HttpsKey); err != nil {
log.Fatalf("Error in HTTPS server: %v", err)
}
}