用 Go (Gin + GORM + SQLite) 重写整个后端: - 单二进制部署,不依赖 Python/pip/SDK - net/http 原生客户端,无 Cloudflare TLS 指纹问题 - 多阶段 Dockerfile:Node 构建前端 + Go 构建后端 + Alpine 运行 - 内存占用从 ~95MB 降至 ~3MB - 完整保留所有 API 路由、JWT 认证、API Key 权限、审计日志
59 lines
1.4 KiB
Go
59 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"airwallex-admin/models"
|
|
"airwallex-admin/services"
|
|
)
|
|
|
|
func GetDashboard(c *gin.Context) {
|
|
// Get daily card limit from settings
|
|
dailyCardLimit := 100
|
|
if v := models.GetSetting(models.DB, "daily_card_limit"); v != "" {
|
|
if n, err := strconv.Atoi(v); err == nil {
|
|
dailyCardLimit = n
|
|
}
|
|
}
|
|
|
|
// Count today's successful card creations
|
|
todayStart := time.Now().UTC().Truncate(24 * time.Hour)
|
|
var todayCardCount int64
|
|
models.DB.Model(&models.CardLog{}).
|
|
Where("action = ? AND status = ? AND created_at >= ?", "create_card", "success", todayStart).
|
|
Count(&todayCardCount)
|
|
|
|
// Get account balance from API
|
|
var accountBalance interface{}
|
|
balance, err := services.GetBalance(models.DB)
|
|
if err == nil {
|
|
accountBalance = balance
|
|
}
|
|
|
|
// Get card counts from API (fetch a large page to count)
|
|
var totalCards, activeCards int
|
|
resp, err := services.ListCards(models.DB, 0, 200, "", "")
|
|
if err == nil {
|
|
if items, ok := resp["items"].([]map[string]interface{}); ok {
|
|
totalCards = len(items)
|
|
for _, item := range items {
|
|
if status, ok := item["card_status"].(string); ok && status == "ACTIVE" {
|
|
activeCards++
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"total_cards": totalCards,
|
|
"active_cards": activeCards,
|
|
"today_card_count": todayCardCount,
|
|
"daily_card_limit": dailyCardLimit,
|
|
"account_balance": accountBalance,
|
|
})
|
|
}
|