104 lines
3.2 KiB
Go
104 lines
3.2 KiB
Go
package main
|
|
|
|
import (
|
|
"backend/common"
|
|
"backend/controller"
|
|
"backend/feishu/server"
|
|
"backend/middleware"
|
|
"backend/model"
|
|
"backend/util"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// GOOS=linux GOARCH=amd64 go build -o /data/backend/release/backend main.go
|
|
|
|
func init() {
|
|
// 以追加模式打开或创建日志文件
|
|
file, err := os.OpenFile("./log/app.log", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0644)
|
|
if err != nil {
|
|
log.Fatalf("failed to open log file: %v", err)
|
|
}
|
|
// 将默认日志输出指向文件
|
|
log.SetOutput(file)
|
|
common.Init()
|
|
}
|
|
|
|
func main() {
|
|
r := gin.Default()
|
|
loginApi := r.Group("/api/auth")
|
|
{
|
|
// 认证
|
|
loginApi.POST("/login", controller.Login)
|
|
loginApi.GET("/Codes", controller.Codes)
|
|
loginApi.POST("/phoneCode", controller.PhoneCode)
|
|
loginApi.POST("/phoneLogin", controller.LoginCode)
|
|
}
|
|
api := r.Group("/api", middleware.ValidateToken())
|
|
{
|
|
|
|
// 账号管理
|
|
api.POST("/admin/list", controller.AdminList)
|
|
api.POST("/admin/add", controller.AdminAdd)
|
|
api.POST("/admin/log/list", controller.AdminLogList)
|
|
// 玩家日志
|
|
api.POST("/log/user", controller.UserDetail)
|
|
api.POST("/log/asset", controller.Asset)
|
|
api.POST("/log/event", controller.Event)
|
|
api.POST("/log/order", controller.Order)
|
|
|
|
// 玩家数据
|
|
api.POST("/user/list", controller.UserList)
|
|
api.GET("/user/info", controller.UserInfo)
|
|
api.POST("/user/gm", controller.UserGM)
|
|
api.POST("/user/ban", controller.UserBan)
|
|
|
|
api.POST("/server/list", controller.AppList)
|
|
api.POST("/server/serverList", controller.ServerList)
|
|
api.POST("/server/addServer", controller.AddServer)
|
|
api.POST("/server/nodeList", controller.NodeList)
|
|
api.POST("/server/addNode", controller.AddNode)
|
|
|
|
api.POST("/server/updateApp", controller.UpdateApp)
|
|
api.POST("/server/updateAppFeishu", controller.UpdateAppFeishu)
|
|
api.POST("/server/restart", controller.RestartServer)
|
|
api.POST("/server/reload", controller.ReloadServer)
|
|
|
|
api.POST("/statistics/level", controller.StatisticsLevel)
|
|
api.POST("/statistics/info", controller.StatisticsInfo)
|
|
api.POST("/statistics/heat", controller.StatisticsHeat)
|
|
|
|
// 邮件
|
|
api.POST("/mail/send", controller.SendMail)
|
|
api.POST("/mail/list", controller.MailList)
|
|
api.POST("/mail/delete", controller.MailDelete)
|
|
|
|
// 飞书
|
|
api.POST("/feishu/sendInfo", controller.FeishuSendInfo)
|
|
api.POST("/feishu/sendInfo2", controller.FeishuSendInfo2)
|
|
api.POST("/feishu/sendWeekInfo", controller.FeishuSendWeekInfo)
|
|
api.POST("/feishu/updateApp", controller.FeishuUpdateApp)
|
|
api.POST("/feishu/serverInfo", controller.FeishuServerInfo)
|
|
api.POST("/feishu/notify", controller.FeishuNotify)
|
|
api.POST("/feishu/notify/client", controller.FeishuNotifyClient)
|
|
}
|
|
go util.ScheduleDailyTask()
|
|
go server.Server()
|
|
go model.InitToken() // 初始化 Token 列表
|
|
go controller.USSendInfo() // 启动定时任务发送信息
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
log.Printf("Recovered from panic: %v", err)
|
|
// 这里可以添加更多的错误处理逻辑,比如发送通知等
|
|
// 重新启动服务器
|
|
fmt.Print("Restarting server...")
|
|
os.Exit(1)
|
|
}
|
|
}()
|
|
// 启动 Gin 服务器
|
|
r.Run(":5320") // 在 0.0.0.0:5320 上监听并服务
|
|
}
|