用 Go (Gin + GORM + SQLite) 重写整个后端: - 单二进制部署,不依赖 Python/pip/SDK - net/http 原生客户端,无 Cloudflare TLS 指纹问题 - 多阶段 Dockerfile:Node 构建前端 + Go 构建后端 + Alpine 运行 - 内存占用从 ~95MB 降至 ~3MB - 完整保留所有 API 路由、JWT 认证、API Key 权限、审计日志
71 lines
1.4 KiB
Go
71 lines
1.4 KiB
Go
package handlers
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"airwallex-admin/models"
|
|
"airwallex-admin/services"
|
|
)
|
|
|
|
var sensitiveKeys = map[string]bool{
|
|
"airwallex_api_key": true,
|
|
"proxy_password": true,
|
|
"admin_password_hash": true,
|
|
}
|
|
|
|
func GetSettings(c *gin.Context) {
|
|
var settings []models.SystemSetting
|
|
models.DB.Find(&settings)
|
|
|
|
for i, s := range settings {
|
|
if sensitiveKeys[s.Key] {
|
|
settings[i].Value = "********"
|
|
}
|
|
}
|
|
|
|
c.JSON(http.StatusOK, settings)
|
|
}
|
|
|
|
type settingItem struct {
|
|
Key string `json:"key"`
|
|
Value string `json:"value"`
|
|
}
|
|
|
|
func UpdateSettings(c *gin.Context) {
|
|
var items []settingItem
|
|
if err := c.ShouldBindJSON(&items); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"detail": "Invalid request body"})
|
|
return
|
|
}
|
|
|
|
for _, item := range items {
|
|
if item.Value == "********" {
|
|
continue
|
|
}
|
|
encrypted := sensitiveKeys[item.Key]
|
|
models.SetSetting(models.DB, item.Key, item.Value, encrypted)
|
|
}
|
|
|
|
username := c.GetString("username")
|
|
models.DB.Create(&models.AuditLog{
|
|
Action: "update_settings",
|
|
ResourceType: "settings",
|
|
Operator: username,
|
|
IPAddress: c.ClientIP(),
|
|
})
|
|
|
|
c.JSON(http.StatusOK, gin.H{"detail": "Settings updated"})
|
|
}
|
|
|
|
func TestConnection(c *gin.Context) {
|
|
result := services.TestConnection(models.DB)
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
func TestProxy(c *gin.Context) {
|
|
result := services.TestProxy(models.DB)
|
|
c.JSON(http.StatusOK, result)
|
|
}
|