功能: - 前台导航: 分类Tab切换、实时搜索、健康状态指示、响应式适配 - 后台管理: 服务/分类CRUD、系统设置、登录认证(bcrypt) - 健康检查: 定时检测(5min)、独立检查URL、三态指示(在线/离线/未检测) - 云端备份: WebDAV上传/下载/恢复/删除、定时自动备份、本地备份管理 技术栈: Go + Gin + GORM + SQLite
47 lines
966 B
Go
47 lines
966 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
Port string
|
|
DBPath string
|
|
SecretKey string
|
|
LogPath string
|
|
WebDAVURL string
|
|
WebDAVUser string
|
|
WebDAVPassword string
|
|
}
|
|
|
|
func LoadConfig() *Config {
|
|
return &Config{
|
|
Port: getEnv("TONAV_PORT", "9520"),
|
|
DBPath: getEnv("TONAV_DB", "tonav.db"),
|
|
SecretKey: getEnv("TONAV_SECRET", "tonav-secret-key-7306783874"),
|
|
LogPath: "tonav.log",
|
|
}
|
|
}
|
|
|
|
func getEnv(key, fallback string) string {
|
|
if value, ok := os.LookupEnv(key); ok {
|
|
return value
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
// ReplaceDB 用备份文件替换当前数据库
|
|
func ReplaceDB(srcPath, dstPath string) error {
|
|
input, err := os.ReadFile(srcPath)
|
|
if err != nil {
|
|
return fmt.Errorf("读取备份文件失败: %v", err)
|
|
}
|
|
if err := os.WriteFile(dstPath, input, 0644); err != nil {
|
|
return fmt.Errorf("替换数据库失败: %v", err)
|
|
}
|
|
// 清理临时文件
|
|
os.Remove(srcPath)
|
|
return nil
|
|
}
|