-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathapiSetup.go
43 lines (38 loc) · 897 Bytes
/
apiSetup.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
package api
import (
"feiyu.com/wx/api/middleware"
"feiyu.com/wx/api/router"
"feiyu.com/wx/srv/srvconfig"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"runtime"
)
func WXServerGinHttpApiStart() error {
app := router.SetUpRouter(func(engine *gin.Engine) {
//获取系统
sysType := runtime.GOOS
if sysType == "linux" {
engine.Use(middleware.BasicAuth())
}
//中间件
engine.Use(middleware.FilterInstanceMiddleware)
engine.Use(middleware.LoggerToFile())
//ginpprof.Wrap(engine)
//中间件需要再创建接口之前完成
//异常处理防止程序奔溃
engine.Use(gin.Recovery())
}, false)
addr := ":" + srvconfig.GlobalSetting.Port
fmt.Println("启动GIN服务成功!", addr)
if srvconfig.GlobalSetting.Pprof {
go func() {
_ = http.ListenAndServe("0.0.0.0:6060", nil)
}()
}
err := app.Run(addr)
if err != nil {
return err
}
return nil
}