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) }