Files
backend/internal/config/server.go

80 lines
3.3 KiB
Go
Raw Normal View History

package config
// ServerConfig 服务器配置
type ServerConfig struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Mode string `mapstructure:"mode"`
}
// LogConfig 日志配置
type LogConfig struct {
Level string `mapstructure:"level"`
Encoding string `mapstructure:"encoding"`
OutputPaths []string `mapstructure:"output_paths"`
Retention LogRetentionConfig `mapstructure:"retention"`
Async AsyncLogConfig `mapstructure:"async"`
Sensitive SensitiveLogConfig `mapstructure:"sensitive"`
Rotation LogRotationConfig `mapstructure:"rotation"`
}
// LogRetentionConfig 日志保留配置
type LogRetentionConfig struct {
AccessLog int `mapstructure:"access_log"` // HTTP访问日志(天)
OperationLog int `mapstructure:"operation_log"` // 操作日志(天)
LoginLog int `mapstructure:"login_log"` // 登录日志(天)
DataChange int `mapstructure:"data_change"` // 数据变更日志(天)
}
// AsyncLogConfig 异步日志配置
type AsyncLogConfig struct {
BufferSize int `mapstructure:"buffer_size"` // 通道缓冲大小
BatchSize int `mapstructure:"batch_size"` // 批量写入大小
FlushInterval string `mapstructure:"flush_interval"` // 刷新间隔
WorkerCount int `mapstructure:"worker_count"` // worker数量
EnableFallback bool `mapstructure:"enable_fallback"` // 启用降级
FallbackPath string `mapstructure:"fallback_path"` // 降级文件路径
}
// SensitiveLogConfig 敏感日志配置
type SensitiveLogConfig struct {
Enabled bool `mapstructure:"enabled"` // 启用脱敏
MaskFields []string `mapstructure:"mask_fields"` // 需脱敏字段
}
// LogRotationConfig 日志轮转配置
type LogRotationConfig struct {
MaxSize int `mapstructure:"max_size"` // 单个文件最大大小(MB)
MaxAge int `mapstructure:"max_age"` // 最大保留天数
MaxBackups int `mapstructure:"max_backups"` // 最大备份数
Compress bool `mapstructure:"compress"` // 压缩
}
// RateLimitConfig 限流配置
type RateLimitConfig struct {
Enabled bool `mapstructure:"enabled"`
RequestsPerMinute int `mapstructure:"requests_per_minute"`
}
// UploadConfig 上传配置
type UploadConfig struct {
MaxFileSize int64 `mapstructure:"max_file_size"`
AllowedTypes []string `mapstructure:"allowed_types"`
}
// FileCleanupConfig 聊天文件 TTL 过期清理配置
type FileCleanupConfig struct {
Enabled bool `mapstructure:"enabled"` // 是否启用清理 worker
RetentionDays int `mapstructure:"retention_days"` // 保留天数,默认 7
IntervalMinutes int `mapstructure:"interval_minutes"` // 扫描间隔(分钟),默认 3606 小时)
BatchSize int `mapstructure:"batch_size"` // 单次扫描处理上限,默认 100
}
// DeviceCleanupConfig 设备 registration_id 清理配置
// 周期性清理超过保留期未使用的设备 token避免无效 registration_id 累积
type DeviceCleanupConfig struct {
Enabled bool `mapstructure:"enabled"` // 是否启用清理 worker默认 true
RetentionDays int `mapstructure:"retention_days"` // 保留天数,默认 33 天不活跃即清理)
IntervalMinutes int `mapstructure:"interval_minutes"` // 扫描间隔(分钟),默认 3606 小时)
}