forked from lejianwen/rustdesk-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp.go
More file actions
41 lines (37 loc) · 1.01 KB
/
http.go
File metadata and controls
41 lines (37 loc) · 1.01 KB
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
package http
import (
"Gwen/global"
"Gwen/http/middleware"
"Gwen/http/router"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
"net/http"
"strings"
)
func ApiInit() {
gin.SetMode(global.Config.Gin.Mode)
g := gin.New()
//[WARNING] You trusted all proxies, this is NOT safe. We recommend you to set a value.
//Please check https://pkg.go.dev/github.com/gin-gonic/gin#readme-don-t-trust-all-proxies for details.
if global.Config.Gin.TrustProxy != "" {
pro := strings.Split(global.Config.Gin.TrustProxy, ",")
err := g.SetTrustedProxies(pro)
if err != nil {
panic(err)
}
}
if global.Config.Gin.Mode == gin.ReleaseMode {
//修改gin Recovery日志 输出为logger的输出点
if global.Logger != nil {
gin.DefaultErrorWriter = global.Logger.WriterLevel(logrus.ErrorLevel)
}
}
g.NoRoute(func(c *gin.Context) {
c.String(http.StatusNotFound, "404 not found")
})
g.Use(middleware.Logger(), gin.Recovery())
router.WebInit(g)
router.Init(g)
router.ApiInit(g)
Run(g, global.Config.Gin.ApiAddr)
}