admin_backend/main.go
2025-11-14 16:08:42 +08:00

120 lines
3.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"backend/common"
"backend/controller"
"backend/feishu/server"
"backend/middleware"
"backend/model"
"backend/util"
"fmt"
"io"
"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)
}
// 将默认日志输出指向文件Go 标准 log
log.SetOutput(file)
// 让 gin 的日志也写入文件,并同时输出到控制台
gin.DefaultWriter = io.MultiWriter(file, os.Stdout)
gin.DefaultErrorWriter = io.MultiWriter(file, os.Stderr)
util.InitBBolt()
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)
}
feishuApi := r.Group("/api/feishu")
{
// 飞书
feishuApi.POST("/sendInfo", controller.FeishuSendInfo)
feishuApi.POST("/sendInfo2", controller.FeishuSendInfo2) // US 运营数据
feishuApi.POST("/sendWeekInfo", controller.FeishuSendWeekInfo)
feishuApi.POST("/updateApp", controller.FeishuUpdateApp)
feishuApi.POST("/serverInfo", controller.FeishuServerInfo)
feishuApi.POST("/notify", controller.FeishuNotify) // 系统报警
feishuApi.POST("/notify/client", controller.FeishuNotifyClient) // 客户端报警
feishuApi.POST("/notify/order", controller.FeishuNotifyOrder) // 订单通知
}
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/order", controller.StatisticsOrder)
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("/language/list", controller.Language)
api.POST("/language/export", controller.LanguageExport)
api.POST("/language/save", controller.LanguageSave)
api.POST("language/add", controller.LanguageAdd)
}
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 上监听并服务
}