Remove `NewRedis` and `NewS3` factory functions from the config package to eliminate unused initialization logic and reduce dependency bloat.
62 lines
1.8 KiB
Go
62 lines
1.8 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
// RedisConfig Redis 配置
|
|
type RedisConfig struct {
|
|
Type string `mapstructure:"type"`
|
|
Redis RedisServerConfig `mapstructure:"redis"`
|
|
Miniredis MiniredisConfig `mapstructure:"miniredis"`
|
|
PoolSize int `mapstructure:"pool_size"`
|
|
}
|
|
|
|
// CacheConfig 缓存配置
|
|
type CacheConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
KeyPrefix string `mapstructure:"key_prefix"`
|
|
DefaultTTL int `mapstructure:"default_ttl"`
|
|
NullTTL int `mapstructure:"null_ttl"`
|
|
JitterRatio float64 `mapstructure:"jitter_ratio"`
|
|
DisableFlushDB bool `mapstructure:"disable_flushdb"`
|
|
Modules CacheModuleTTL `mapstructure:"modules"`
|
|
Local LocalCacheConfig `mapstructure:"local"`
|
|
}
|
|
|
|
// LocalCacheConfig 本地缓存配置
|
|
type LocalCacheConfig struct {
|
|
Enabled bool `mapstructure:"enabled"`
|
|
Size int `mapstructure:"size"`
|
|
Buckets int `mapstructure:"buckets"`
|
|
DefaultTTL int `mapstructure:"default_ttl"`
|
|
}
|
|
|
|
// CacheModuleTTL 缓存模块 TTL 配置
|
|
type CacheModuleTTL struct {
|
|
PostList int `mapstructure:"post_list_ttl"`
|
|
Conversation int `mapstructure:"conversation_ttl"`
|
|
UnreadCount int `mapstructure:"unread_count_ttl"`
|
|
GroupMembers int `mapstructure:"group_members_ttl"`
|
|
}
|
|
|
|
// RedisServerConfig Redis 服务器配置
|
|
type RedisServerConfig struct {
|
|
Host string `mapstructure:"host"`
|
|
Port int `mapstructure:"port"`
|
|
Password string `mapstructure:"password"`
|
|
DB int `mapstructure:"db"`
|
|
}
|
|
|
|
// Addr 返回 Redis 服务器地址
|
|
func (r RedisServerConfig) Addr() string {
|
|
return fmt.Sprintf("%s:%d", r.Host, r.Port)
|
|
}
|
|
|
|
// MiniredisConfig Miniredis 配置(用于测试)
|
|
type MiniredisConfig struct {
|
|
Host string `mapstructure:"host"`
|
|
Port int `mapstructure:"port"`
|
|
}
|
|
|