refactor: Enhance texture handling and configuration

- Removed Swagger documentation import from the main server file.
- Updated TextureInfo struct to include UploaderUsername for better texture metadata.
- Modified texture repository methods to preload Uploader information when fetching textures by hash.
- Improved texture service to handle cases where Uploader information is missing, ensuring proper caching and retrieval.
- Added Redis configuration options in the environment variable setup for better flexibility.
This commit is contained in:
lafay
2026-01-10 03:15:27 +08:00
parent e761ff5be5
commit c5db489d72
7 changed files with 80 additions and 41 deletions

View File

@@ -131,13 +131,14 @@ type SecurityConfig struct {
// Load 加载配置 - 完全从环境变量加载不依赖YAML文件
func Load() (*Config, error) {
// 加载.env文件如果存在
_ = godotenv.Load(".env")
if err := godotenv.Load(".env"); err != nil {
fmt.Printf("警告: 无法加载 .env 文件: %v\n", err)
}
// 设置默认值
setDefaults()
// 设置环境变量前缀
viper.SetEnvPrefix("CARROTSKIN")
// 自动读取环境变量(不设置前缀,因为 BindEnv 已经明确指定了变量名)
viper.AutomaticEnv()
// 手动设置环境变量映射
@@ -302,6 +303,7 @@ func setupEnvMappings() {
// overrideFromEnv 从环境变量中覆盖配置
func overrideFromEnv(config *Config) {
// 处理RustFS存储桶配置
if texturesBucket := os.Getenv("RUSTFS_BUCKET_TEXTURES"); texturesBucket != "" {
if config.RustFS.Buckets == nil {
@@ -342,6 +344,24 @@ func overrideFromEnv(config *Config) {
}
}
// 处理Redis基本配置
if host := os.Getenv("REDIS_HOST"); host != "" {
config.Redis.Host = host
}
if port := os.Getenv("REDIS_PORT"); port != "" {
if val, err := strconv.Atoi(port); err == nil {
config.Redis.Port = val
}
}
if password := os.Getenv("REDIS_PASSWORD"); password != "" {
config.Redis.Password = password
}
if database := os.Getenv("REDIS_DATABASE"); database != "" {
if val, err := strconv.Atoi(database); err == nil {
config.Redis.Database = val
}
}
// 处理Redis连接池配置
if poolSize := os.Getenv("REDIS_POOL_SIZE"); poolSize != "" {
if val, err := strconv.Atoi(poolSize); err == nil {