用 Go (Gin + GORM + SQLite) 重写整个后端: - 单二进制部署,不依赖 Python/pip/SDK - net/http 原生客户端,无 Cloudflare TLS 指纹问题 - 多阶段 Dockerfile:Node 构建前端 + Go 构建后端 + Alpine 运行 - 内存占用从 ~95MB 降至 ~3MB - 完整保留所有 API 路由、JWT 认证、API Key 权限、审计日志
38 lines
1015 B
Go
38 lines
1015 B
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
)
|
|
|
|
type SystemSetting struct {
|
|
ID uint `json:"id" gorm:"primaryKey;autoIncrement"`
|
|
Key string `json:"key" gorm:"column:key;type:varchar(255);uniqueIndex:ix_system_settings_key;not null"`
|
|
Value string `json:"value" gorm:"type:text;not null"`
|
|
Encrypted bool `json:"encrypted" gorm:"not null"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"not null;autoUpdateTime"`
|
|
}
|
|
|
|
func GetSetting(db *gorm.DB, key string) string {
|
|
var setting SystemSetting
|
|
result := db.Where("`key` = ?", key).First(&setting)
|
|
if result.Error != nil {
|
|
return ""
|
|
}
|
|
return setting.Value
|
|
}
|
|
|
|
func SetSetting(db *gorm.DB, key, value string, encrypted bool) {
|
|
setting := SystemSetting{
|
|
Key: key,
|
|
Value: value,
|
|
Encrypted: encrypted,
|
|
}
|
|
db.Clauses(clause.OnConflict{
|
|
Columns: []clause.Column{{Name: "key"}},
|
|
DoUpdates: clause.AssignmentColumns([]string{"value", "encrypted", "updated_at"}),
|
|
}).Create(&setting)
|
|
}
|