-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
40 lines (31 loc) · 1.04 KB
/
main.go
File metadata and controls
40 lines (31 loc) · 1.04 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
package main
import (
"OptiOJ/src/config"
"OptiOJ/src/routes"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
)
func main() {
config.InitConfig()
// 设置 logrus 日志格式
logrus.SetFormatter(&logrus.TextFormatter{
FullTimestamp: true,
})
config.InitDB()
config.InitRedis()
r := gin.Default()
// 配置 CORS 规则
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"*"}, // 允许所有来源
AllowMethods: []string{"GET", "POST", "PUT", "DELETE"}, // 允许的方法
AllowHeaders: []string{"Origin", "Content-Type", "Authorization"}, // 允许的请求头
ExposeHeaders: []string{"Content-Length"}, // 允许暴露的响应头
AllowCredentials: true, // 允许携带凭证
}))
routes.SetupRoutes(r)
logrus.Info("服务器启动,监听端口 2550")
if err := r.Run(":2550"); err != nil {
logrus.Fatal("服务器启动失败: ", err)
}
}