-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.go
89 lines (77 loc) · 2.16 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/wonderivan/logger"
"ops-api/config"
"ops-api/controller/routers"
"ops-api/db"
"ops-api/global"
"ops-api/middleware"
"ops-api/service"
)
func main() {
// 配置初始化
config.Init()
// 初始化MySQL
if err := db.MySQLInit(); err != nil {
logger.Error("ERROR:", err.Error())
return
}
// 初始Redis
if err := db.RedisInit(); err != nil {
logger.Error("ERROR:", err.Error())
return
}
// 初始化Minio
if err := db.MinioInit(); err != nil {
logger.Error("ERROR:", err.Error())
return
}
// 初始化CasBin权限
if err := middleware.CasBinInit(); err != nil {
logger.Error("ERROR:", err.Error())
return
}
// 初始化定时任务
if err := service.TaskInit(); err != nil {
logger.Error("ERROR:", err.Error())
return
}
r := gin.Default()
// 加载跨域中间件
r.Use(middleware.Cors())
// 加载登录中间件,其中IgnorePaths()方法可以忽略不需要登录认证的路由,支持前缀匹配
r.Use(middleware.LoginBuilder().
IgnorePaths("/api/auth/login").
IgnorePaths("/health").
IgnorePaths("/swagger/").
IgnorePaths("/api/v1/sms/huawei/callback").
IgnorePaths("/api/v1/sms/reset_password").
IgnorePaths("/api/v1/reset_password").
IgnorePaths("/api/v1/user/mfa_qrcode").
IgnorePaths("/api/v1/user/mfa_auth").
IgnorePaths("/api/v1/sso/oauth/token").
IgnorePaths("/api/v1/sso/oauth/userinfo").
IgnorePaths("/p3/serviceValidate").
IgnorePaths("/api/v1/sso/saml/metadata").
IgnorePaths("/api/v1/sso/saml/authorize").
IgnorePaths("/.well-known/openid-configuration").
IgnorePaths("/api/v1/sso/oidc/jwks").
IgnorePaths("/api/v1/sso/cookie/auth").
IgnorePaths("/api/auth/dingtalk_login").
IgnorePaths("/api/auth/ww_login").
IgnorePaths("/api/auth/feishu_login").
IgnorePaths("/api/v1/site/guide").
Build())
// 加载权限中间件
r.Use(middleware.PermissionCheck())
// 加载记录日志中间件
r.Use(middleware.Oplog(global.MySQLClient))
// 注册路由
routers.Router.InitRouter(r)
// 启动服务
if err := r.Run(fmt.Sprintf("%v", config.Conf.Server)); err != nil {
logger.Error("ERROR:", err.Error())
}
}