-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (46 loc) · 1.27 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
package main
import (
"context"
"github.com/gin-gonic/gin"
"github.com/lesismal/nbio/nbhttp"
"os"
"os/signal"
"rhyus-golang/api"
"rhyus-golang/common"
"rhyus-golang/conf"
"rhyus-golang/middlewares"
"rhyus-golang/service"
"strconv"
"time"
)
func main() {
service.StartPProfServe()
gin.SetMode(gin.ReleaseMode)
ginServer := gin.New()
ginServer.UseH2C = true
ginServer.MaxMultipartMemory = 1024 * 1024 * 32 // 表示处理上传的文件时,最多将32MB的数据保存在内存中,超出部分会保存到临时文件中。这样可以避免大文件上传时占用过多内存。
ginServer.Use(
middlewares.Recover,
middlewares.Logging,
middlewares.CorsMiddleware,
middlewares.Authorize,
)
api.ServeAPI(ginServer)
addr := conf.Conf.Host + ":" + strconv.Itoa(conf.Conf.Port)
engine := nbhttp.NewEngine(nbhttp.Config{
Network: "tcp",
Addrs: []string{addr},
Handler: ginServer,
})
common.Log.Info("server start at: %s", addr)
err := engine.Start()
if err != nil {
common.Log.Fatal(common.ExitCodeUnavailablePort, "serve start failed: %s", err)
}
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
<-interrupt
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
engine.Shutdown(ctx)
}