Files
Airwallex/models/init.go
zqq61 faba565c66 feat: Go 重写后端,替换 Python FastAPI
用 Go (Gin + GORM + SQLite) 重写整个后端:
- 单二进制部署,不依赖 Python/pip/SDK
- net/http 原生客户端,无 Cloudflare TLS 指纹问题
- 多阶段 Dockerfile:Node 构建前端 + Go 构建后端 + Alpine 运行
- 内存占用从 ~95MB 降至 ~3MB
- 完整保留所有 API 路由、JWT 认证、API Key 权限、审计日志
2026-03-16 02:11:48 +08:00

41 lines
1.0 KiB
Go

package models
import (
"log"
"os"
"airwallex-admin/config"
"golang.org/x/crypto/bcrypt"
"gorm.io/gorm"
)
func InitializeDefaults(db *gorm.DB) {
// Set admin password hash if not already set
if GetSetting(db, "admin_password_hash") == "" {
hash, err := bcrypt.GenerateFromPassword([]byte(config.Cfg.AdminPassword), bcrypt.DefaultCost)
if err != nil {
log.Fatalf("failed to hash admin password: %v", err)
}
SetSetting(db, "admin_password_hash", string(hash), false)
}
// Set default daily card limit
if GetSetting(db, "daily_card_limit") == "" {
SetSetting(db, "daily_card_limit", "100", false)
}
// Store Airwallex credentials from environment if not already set
envSettings := map[string]string{
"airwallex_client_id": os.Getenv("AIRWALLEX_CLIENT_ID"),
"airwallex_api_key": os.Getenv("AIRWALLEX_API_KEY"),
"airwallex_base_url": os.Getenv("AIRWALLEX_BASE_URL"),
}
for key, value := range envSettings {
if value != "" && GetSetting(db, key) == "" {
SetSetting(db, key, value, key != "airwallex_base_url")
}
}
}