golang-yitisheng-server/server/config/config.go

73 lines
1.8 KiB
Go

// Package config 应用配置
package config
// AppConfig 应用配置
var AppConfig = &appConfig{
// 日志配置
Log: LogConfig{
Level: "debug", // debug/info/warn/error
Dir: "logs", // 日志目录
Console: true, // 是否同时输出到控制台
},
// 安全配置
Security: SecurityConfig{
Enable: true, // 是否启用安全校验
HeaderKey: "X-App-Sign", // 请求头校验字段
SecretKey: "yts@2025#secure", // 签名密钥
},
// 限流配置
RateLimit: RateLimitConfig{
Enable: true,
Default: RateLimitRule{Interval: 2, MaxRequests: 3}, // 默认2秒1次
Rules: map[string]RateLimitRule{
"/api/auth/login": {Interval: 5, MaxRequests: 1}, // 登录5秒1次
"/api/yx-school-majors": {Interval: 1, MaxRequests: 5}, // 查询1秒5次
},
},
// Swagger配置
Swagger: SwaggerConfig{
User: "admin",
Password: "password",
},
}
type appConfig struct {
Log LogConfig
Security SecurityConfig
RateLimit RateLimitConfig
Swagger SwaggerConfig
}
// LogConfig 日志配置
type LogConfig struct {
Level string // 日志级别
Dir string // 日志目录
Console bool // 是否输出到控制台
}
// SecurityConfig 安全配置
type SecurityConfig struct {
Enable bool // 是否启用
HeaderKey string // 请求头字段名
SecretKey string // 签名密钥
}
// RateLimitConfig 限流配置
type RateLimitConfig struct {
Enable bool // 是否启用
Default RateLimitRule // 默认规则
Rules map[string]RateLimitRule // 特定路径规则
}
// RateLimitRule 限流规则
type RateLimitRule struct {
Interval int // 时间间隔(秒)
MaxRequests int // 最大请求次数
}
// SwaggerConfig Swagger文档认证配置
type SwaggerConfig struct {
User string
Password string
}