-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.go
More file actions
41 lines (38 loc) · 963 Bytes
/
app.go
File metadata and controls
41 lines (38 loc) · 963 Bytes
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 main
import (
"github.com/100steps/gin-layout/controller"
"github.com/100steps/gin-layout/cron"
"github.com/100steps/gin-layout/middleware"
"github.com/forseason/env"
"github.com/gin-gonic/gin"
)
// 生成app容器并加载依赖的函数,这一层应当注入控制器依赖
func newApp(
middleware *middleware.Middleware,
crontab *cron.Cron,
userController *controller.UserController,
) *app {
switch env.Get("SERVER_MODE", "debug") {
case "release":
gin.SetMode(gin.ReleaseMode)
case "test":
gin.SetMode(gin.TestMode)
default:
gin.SetMode(gin.DebugMode)
}
app := &app{
r: gin.New(),
middleware: middleware,
crontab: crontab,
userController: userController,
}
app.initRouter()
return app
}
// 这里也要记得添加上对应的属性
type app struct {
r *gin.Engine
middleware *middleware.Middleware
crontab *cron.Cron
userController *controller.UserController
}