用 Go (Gin + GORM + SQLite) 重写整个后端: - 单二进制部署,不依赖 Python/pip/SDK - net/http 原生客户端,无 Cloudflare TLS 指纹问题 - 多阶段 Dockerfile:Node 构建前端 + Go 构建后端 + Alpine 运行 - 内存占用从 ~95MB 降至 ~3MB - 完整保留所有 API 路由、JWT 认证、API Key 权限、审计日志
96 lines
2.0 KiB
Go
96 lines
2.0 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"airwallex-admin/models"
|
|
)
|
|
|
|
func ListCardLogs(c *gin.Context) {
|
|
pageNum, _ := strconv.Atoi(c.DefaultQuery("page_num", "0"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
|
|
query := models.DB.Model(&models.CardLog{})
|
|
|
|
if v := c.Query("card_id"); v != "" {
|
|
query = query.Where("card_id = ?", v)
|
|
}
|
|
if v := c.Query("action"); v != "" {
|
|
query = query.Where("action = ?", v)
|
|
}
|
|
|
|
var total int64
|
|
query.Count(&total)
|
|
|
|
var logs []models.CardLog
|
|
query.Order("created_at DESC").
|
|
Offset(pageNum * pageSize).
|
|
Limit(pageSize).
|
|
Find(&logs)
|
|
|
|
if logs == nil {
|
|
logs = []models.CardLog{}
|
|
}
|
|
|
|
hasMore := int64((pageNum+1)*pageSize) < total
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"items": logs,
|
|
"page_num": pageNum,
|
|
"page_size": pageSize,
|
|
"total": total,
|
|
"has_more": hasMore,
|
|
})
|
|
}
|
|
|
|
func ListAuditLogs(c *gin.Context) {
|
|
pageNum, _ := strconv.Atoi(c.DefaultQuery("page_num", "0"))
|
|
pageSize, _ := strconv.Atoi(c.DefaultQuery("page_size", "20"))
|
|
|
|
query := models.DB.Model(&models.AuditLog{})
|
|
|
|
if v := c.Query("action"); v != "" {
|
|
query = query.Where("action = ?", v)
|
|
}
|
|
if v := c.Query("resource_type"); v != "" {
|
|
query = query.Where("resource_type = ?", v)
|
|
}
|
|
if v := c.Query("from_date"); v != "" {
|
|
if t, err := time.Parse("2006-01-02", v); err == nil {
|
|
query = query.Where("created_at >= ?", t)
|
|
}
|
|
}
|
|
if v := c.Query("to_date"); v != "" {
|
|
if t, err := time.Parse("2006-01-02", v); err == nil {
|
|
query = query.Where("created_at < ?", t.Add(24*time.Hour))
|
|
}
|
|
}
|
|
|
|
var total int64
|
|
query.Count(&total)
|
|
|
|
var logs []models.AuditLog
|
|
query.Order("created_at DESC").
|
|
Offset(pageNum * pageSize).
|
|
Limit(pageSize).
|
|
Find(&logs)
|
|
|
|
if logs == nil {
|
|
logs = []models.AuditLog{}
|
|
}
|
|
|
|
hasMore := int64((pageNum+1)*pageSize) < total
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"items": logs,
|
|
"page_num": pageNum,
|
|
"page_size": pageSize,
|
|
"total": total,
|
|
"has_more": hasMore,
|
|
})
|
|
}
|