-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (56 loc) · 1.28 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
package main
import (
"gtest/endless"
mdw "gtest/middleware"
"io"
"log"
"net/http"
"os"
"time"
"github.com/gin-gonic/gin"
)
func main() {
if os.Getenv("APP_ENV") == "DEPLOYED" {
i := getLogger()
// i.Rotate()
gin.DisableConsoleColor()
gin.DefaultWriter = io.MultiWriter(i)
log.SetOutput(i)
}
r := gin.Default()
r.Use(mdw.CORS())
// r.Use(mdw.AuthAPIKey())
// r.Use(mdw.Auth0())
router(r)
if os.Getenv("APP_ENV") != "DEPLOYED" {
server := &http.Server{
Addr: os.Getenv("PORT"),
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.Method == "HEAD" {
req.Method = "GET"
}
r.ServeHTTP(w, req)
}),
// Handler: r,
ReadTimeout: 60 * time.Second,
WriteTimeout: 60 * time.Second,
MaxHeaderBytes: 1 << 20, // 1 MB
}
log.Fatal("failed to start server: ", server.ListenAndServe())
} else {
endless.DefaultHammerTime = -1
endless.DefaultReadTimeOut = 60 * time.Second
endless.DefaultWriteTimeOut = 60 * time.Second
endless.DefaultMaxHeaderBytes = 1 << 20
server := endless.NewServer(
os.Getenv("PORT"),
http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
if req.Method == "HEAD" {
req.Method = "GET"
}
r.ServeHTTP(w, req)
}),
)
server.ListenAndServe()
}
}