更新项目配置,修改 Go 版本至 1.24,添加依赖项,重构主程序以加载配置和初始化服务,删除不再使用的远程目标配置文件。

This commit is contained in:
zeaslity
2025-03-13 10:07:40 +08:00
parent 6d5eb4bba5
commit 0090801298
20 changed files with 1424 additions and 129 deletions

View File

@@ -0,0 +1,48 @@
package config
import (
"sync"
)
// Config 配置结构体
type Config struct {
Server struct {
Port string `mapstructure:"port"`
} `mapstructure:"server"`
Auth struct {
Secret string `mapstructure:"secret"` // TOTP密钥
AuthFilePath string `mapstructure:"auth_file"` // 授权文件路径
TimeOffsetAllowed int64 `mapstructure:"time_offset_allowed"` // 允许的时间偏移(秒)
} `mapstructure:"auth"`
WatchdogCenter struct {
URL string `mapstructure:"url"` // 一级授权中心地址
} `mapstructure:"watchdog_center"`
}
var (
config Config
once sync.Once
)
// LoadConfig 加载配置
func LoadConfig(path string) error {
once.Do(func() {
// 设置默认配置值
config.Server.Port = "8080"
config.Auth.Secret = "default-secret-key-please-change-in-production"
config.Auth.AuthFilePath = "./auth-storage.json"
config.Auth.TimeOffsetAllowed = 3600 // 默认允许1小时的时间偏移
config.WatchdogCenter.URL = "http://localhost:8081"
// 这里可以添加从文件加载配置的逻辑比如使用标准库读取JSON或YAML文件
// 但目前使用默认值替代
})
return nil
}
// GetConfig 获取配置
func GetConfig() *Config {
return &config
}