refactor(config): 移除已废弃的配置字段
移除以下已标记废弃的字段: - AuthConfig.MinPasswordLength (auth) - FileCacheConfig.LRUEviction (file_cache) - TransportConfig.MaxIdleConns (transport) 同时清理相关的验证逻辑、默认值设置、测试代码和文档。 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
b30c84a38b
commit
ee4f7a5ca9
@ -470,7 +470,6 @@ next_upstream:
|
||||
| `max_entries` | int64 | `10000` | 最大缓存条目数 |
|
||||
| `max_size` | int64 | `268435456` (256MB) | 内存上限 |
|
||||
| `inactive` | duration | `20s` | 未访问淘汰时间 |
|
||||
| `lru_eviction` | bool | - | **已废弃,请使用 max_size** |
|
||||
|
||||
### TransportConfig
|
||||
|
||||
|
||||
@ -1041,7 +1041,6 @@ cache:
|
||||
max_entries: 10000
|
||||
max_size: 256MB # 内存上限
|
||||
inactive: 20s
|
||||
lru_eviction: true # 启用 LRU 淘汰
|
||||
|
||||
proxy:
|
||||
enabled: true
|
||||
|
||||
@ -743,10 +743,6 @@ type AuthConfig struct {
|
||||
// Realm 认证域
|
||||
// 显示在浏览器认证对话框中的描述信息
|
||||
Realm string `yaml:"realm"`
|
||||
|
||||
// MinPasswordLength 密码最小长度
|
||||
// Deprecated: 该字段已废弃,将在未来版本中移除。密码长度验证应在密码哈希生成阶段进行
|
||||
MinPasswordLength int `yaml:"min_password_length"`
|
||||
}
|
||||
|
||||
// User 认证用户配置。
|
||||
@ -1087,7 +1083,6 @@ type GoroutinePoolConfig struct {
|
||||
// - MaxEntries 限制最大缓存文件数量
|
||||
// - MaxSize 限制缓存总内存使用量(字节)
|
||||
// - Inactive 超过此时间未访问的文件将被淘汰
|
||||
// - LRUEviction 已废弃,请使用 MaxSize
|
||||
//
|
||||
// 使用示例:
|
||||
//
|
||||
@ -1107,10 +1102,6 @@ type FileCacheConfig struct {
|
||||
// Inactive 未访问淘汰时间
|
||||
// 超过此时间未被访问的缓存将被清除
|
||||
Inactive time.Duration `yaml:"inactive"`
|
||||
|
||||
// LRUEviction 启用 LRU 淘汰
|
||||
// Deprecated: 该字段已废弃,将在未来版本中移除,请使用 MaxSize 代替
|
||||
LRUEviction bool `yaml:"lru_eviction"`
|
||||
}
|
||||
|
||||
// TransportConfig HTTP Transport 配置。
|
||||
@ -1118,7 +1109,6 @@ type FileCacheConfig struct {
|
||||
// 配置代理后端连接的连接池参数。
|
||||
//
|
||||
// 注意事项:
|
||||
// - MaxIdleConns 控制所有主机的总空闲连接数
|
||||
// - MaxIdleConnsPerHost 控制每个后端主机的空闲连接
|
||||
// - IdleConnTimeout 控制空闲连接的保持时间
|
||||
// - MaxConnsPerHost 限制每个后端主机的总连接数
|
||||
@ -1126,15 +1116,10 @@ type FileCacheConfig struct {
|
||||
// 使用示例:
|
||||
//
|
||||
// transport:
|
||||
// max_idle_conns: 100
|
||||
// max_idle_conns_per_host: 10
|
||||
// idle_conn_timeout: 90s
|
||||
// max_conns_per_host: 100
|
||||
type TransportConfig struct {
|
||||
// MaxIdleConns 最大空闲连接数
|
||||
// Deprecated: 该字段已废弃,fasthttp.HostClient 不支持此参数,请使用 MaxConnsPerHost 代替
|
||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
||||
|
||||
// MaxIdleConnsPerHost 每主机最大空闲连接
|
||||
// 单个后端主机的最大空闲连接数
|
||||
MaxIdleConnsPerHost int `yaml:"max_idle_conns_per_host"`
|
||||
|
||||
@ -75,10 +75,9 @@ func DefaultConfig() *Config {
|
||||
SlidingWindow: 60,
|
||||
},
|
||||
Auth: AuthConfig{
|
||||
RequireTLS: true,
|
||||
Algorithm: "bcrypt",
|
||||
Realm: "Restricted Area",
|
||||
MinPasswordLength: 0, // 已废弃,不再使用
|
||||
RequireTLS: true,
|
||||
Algorithm: "bcrypt",
|
||||
Realm: "Restricted Area",
|
||||
},
|
||||
Headers: SecurityHeaders{
|
||||
XFrameOptions: "DENY",
|
||||
@ -126,7 +125,6 @@ func DefaultConfig() *Config {
|
||||
Inactive: 20 * time.Second,
|
||||
},
|
||||
Transport: TransportConfig{
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 32,
|
||||
IdleConnTimeout: 90 * time.Second,
|
||||
MaxConnsPerHost: 0, // 0 表示不限制
|
||||
@ -290,7 +288,6 @@ func GenerateConfigYAML(cfg *Config) ([]byte, error) {
|
||||
fmt.Fprintf(&buf, " algorithm: \"%s\" # 密码哈希算法(有效值: bcrypt, argon2id)\n", cfg.Server.Security.Auth.Algorithm)
|
||||
buf.WriteString(" users: [] # 用户列表\n")
|
||||
fmt.Fprintf(&buf, " realm: \"%s\" # 认证域\n", cfg.Server.Security.Auth.Realm)
|
||||
fmt.Fprintf(&buf, " min_password_length: %d # 密码最小长度\n", cfg.Server.Security.Auth.MinPasswordLength)
|
||||
buf.WriteString("\n")
|
||||
buf.WriteString(" # 安全头部\n")
|
||||
buf.WriteString(" headers:\n")
|
||||
@ -428,7 +425,6 @@ func GenerateConfigYAML(cfg *Config) ([]byte, error) {
|
||||
fmt.Fprintf(&buf, " max_size: %d # 内存上限(字节,%dMB)\n", cfg.Performance.FileCache.MaxSize, cfg.Performance.FileCache.MaxSize/1024/1024)
|
||||
fmt.Fprintf(&buf, " inactive: %ds # 未访问淘汰时间\n", int(cfg.Performance.FileCache.Inactive.Seconds()))
|
||||
buf.WriteString(" transport: # HTTP Transport 连接池\n")
|
||||
fmt.Fprintf(&buf, " max_idle_conns: %d # 最大空闲连接\n", cfg.Performance.Transport.MaxIdleConns)
|
||||
fmt.Fprintf(&buf, " max_idle_conns_per_host: %d # 每主机空闲连接\n", cfg.Performance.Transport.MaxIdleConnsPerHost)
|
||||
fmt.Fprintf(&buf, " idle_conn_timeout: %ds # 空闲超时\n", int(cfg.Performance.Transport.IdleConnTimeout.Seconds()))
|
||||
fmt.Fprintf(&buf, " max_conns_per_host: %d # 每主机最大连接(0 表示不限制)\n", cfg.Performance.Transport.MaxConnsPerHost)
|
||||
|
||||
@ -119,12 +119,8 @@ func TestDefaultConfigPerformance(t *testing.T) {
|
||||
if cfg.Performance.FileCache.Inactive != 20*time.Second {
|
||||
t.Errorf("FileCache.Inactive 期望 20s, 实际 %v", cfg.Performance.FileCache.Inactive)
|
||||
}
|
||||
// 注意: LRUEviction 已废弃,不再验证
|
||||
|
||||
// 验证 Transport 默认值
|
||||
if cfg.Performance.Transport.MaxIdleConns != 100 {
|
||||
t.Errorf("Transport.MaxIdleConns 期望 100, 实际 %d", cfg.Performance.Transport.MaxIdleConns)
|
||||
}
|
||||
if cfg.Performance.Transport.MaxIdleConnsPerHost != 32 {
|
||||
t.Errorf("Transport.MaxIdleConnsPerHost 期望 32, 实际 %d", cfg.Performance.Transport.MaxIdleConnsPerHost)
|
||||
}
|
||||
|
||||
@ -21,7 +21,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"rua.plus/lolly/internal/loadbalance"
|
||||
@ -380,11 +379,6 @@ func validateAccess(a *AccessConfig) error {
|
||||
// - algorithm 仅支持 bcrypt 或 argon2id
|
||||
// - 启用认证时至少需要一个用户
|
||||
func validateAuth(a *AuthConfig) error {
|
||||
// 检查废弃的 MinPasswordLength 字段
|
||||
if a.MinPasswordLength > 0 {
|
||||
fmt.Fprintln(os.Stderr, "[警告] security.auth.min_password_length 已废弃,将在未来版本中移除。密码长度验证应在密码哈希生成阶段进行")
|
||||
}
|
||||
|
||||
// 未配置认证时跳过
|
||||
if a.Type == "" {
|
||||
return nil
|
||||
@ -729,20 +723,7 @@ func validateStream(s *StreamConfig) error {
|
||||
// 返回值:
|
||||
// - error: 验证失败时返回错误信息,成功返回 nil
|
||||
func validatePerformance(p *PerformanceConfig) error {
|
||||
// 检查废弃的 LRUEviction 字段
|
||||
if p.FileCache.LRUEviction {
|
||||
fmt.Fprintln(os.Stderr, "[警告] performance.file_cache.lru_eviction 已废弃,请使用 max_size 代替")
|
||||
}
|
||||
|
||||
// 检查废弃的 MaxIdleConns 字段
|
||||
if p.Transport.MaxIdleConns > 0 {
|
||||
fmt.Fprintln(os.Stderr, "[警告] performance.transport.max_idle_conns 已废弃,fasthttp 不支持此参数,请使用 max_conns_per_host 代替")
|
||||
}
|
||||
|
||||
// 检查 Transport 配置(可能导致性能问题)
|
||||
if p.Transport.MaxIdleConns < 0 {
|
||||
return errors.New("transport.max_idle_conns 不能为负数")
|
||||
}
|
||||
if p.Transport.MaxIdleConnsPerHost < 0 {
|
||||
return errors.New("transport.max_idle_conns_per_host 不能为负数")
|
||||
}
|
||||
|
||||
@ -1000,7 +1000,6 @@ func TestValidatePerformance(t *testing.T) {
|
||||
name: "有效的 transport 配置(零值)",
|
||||
config: PerformanceConfig{
|
||||
Transport: TransportConfig{
|
||||
MaxIdleConns: 0,
|
||||
MaxIdleConnsPerHost: 0,
|
||||
MaxConnsPerHost: 0,
|
||||
},
|
||||
@ -1011,32 +1010,12 @@ func TestValidatePerformance(t *testing.T) {
|
||||
name: "有效的 transport 配置(正值)",
|
||||
config: PerformanceConfig{
|
||||
Transport: TransportConfig{
|
||||
MaxIdleConns: 100,
|
||||
MaxIdleConnsPerHost: 10,
|
||||
MaxConnsPerHost: 50,
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "LRUEviction=true(废弃警告)",
|
||||
config: PerformanceConfig{
|
||||
FileCache: FileCacheConfig{
|
||||
LRUEviction: true,
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "MaxIdleConns 负数",
|
||||
config: PerformanceConfig{
|
||||
Transport: TransportConfig{
|
||||
MaxIdleConns: -1,
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
errMsg: "transport.max_idle_conns 不能为负数",
|
||||
},
|
||||
{
|
||||
name: "MaxIdleConnsPerHost 负数",
|
||||
config: PerformanceConfig{
|
||||
@ -1061,13 +1040,12 @@ func TestValidatePerformance(t *testing.T) {
|
||||
name: "多个 transport 字段为负",
|
||||
config: PerformanceConfig{
|
||||
Transport: TransportConfig{
|
||||
MaxIdleConns: -1,
|
||||
MaxIdleConnsPerHost: -2,
|
||||
MaxConnsPerHost: -3,
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
errMsg: "transport.max_idle_conns 不能为负数",
|
||||
errMsg: "transport.max_idle_conns_per_host 不能为负数",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@ -67,9 +67,6 @@ type BasicAuth struct {
|
||||
// requireTLS 是否强制 HTTPS(默认 true)
|
||||
requireTLS bool
|
||||
|
||||
// minPasswordLength 密码最小长度(用于验证)
|
||||
minPasswordLength int
|
||||
|
||||
// argon2Params Argon2id 配置参数
|
||||
argon2Params argon2Params
|
||||
|
||||
@ -124,10 +121,9 @@ func NewBasicAuth(cfg *config.AuthConfig) (*BasicAuth, error) {
|
||||
}
|
||||
|
||||
auth := &BasicAuth{
|
||||
users: make(map[string]string),
|
||||
requireTLS: cfg.RequireTLS, // Default is true from config defaults
|
||||
minPasswordLength: cfg.MinPasswordLength,
|
||||
argon2Params: defaultArgon2Params,
|
||||
users: make(map[string]string),
|
||||
requireTLS: cfg.RequireTLS, // Default is true from config defaults
|
||||
argon2Params: defaultArgon2Params,
|
||||
}
|
||||
|
||||
// 设置认证域
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user