From 6f17bbad7e61efb19e2d945e7daa98a841cb1eb4 Mon Sep 17 00:00:00 2001 From: xfy Date: Wed, 3 Jun 2026 18:08:34 +0800 Subject: [PATCH] chore: remove trailing blank lines and clean up whitespace --- gjson/config.go | 2 - gjson/gjson.go | 2 - internal/app/app_test.go | 40 ------------------- internal/app/testutil.go | 3 -- internal/cache/cache_test.go | 2 - internal/config/config.go | 32 +++++++-------- internal/config/config_test.go | 5 --- internal/config/defaults_test.go | 2 - internal/handler/static_test.go | 4 +- internal/http2/adapter.go | 2 - internal/http2/integration_tls_test.go | 6 --- internal/http2/server.go | 2 - internal/http2/server_bench_test.go | 1 - internal/http3/adapter.go | 2 - internal/http3/server.go | 2 - internal/http3/server_test.go | 4 -- internal/integration/e2e_bench_test.go | 6 +-- internal/loadbalance/slow_start.go | 2 - internal/loadbalance/slow_start_test.go | 2 - internal/lua/api_location.go | 2 - internal/lua/api_log.go | 6 +-- internal/lua/api_req.go | 2 - internal/lua/api_resp.go | 2 - internal/lua/api_var.go | 2 - internal/lua/middleware_config.go | 2 - internal/lua/register.go | 2 - internal/matcher/location.go | 2 - internal/matcher/location_test.go | 4 -- internal/matcher/matcher.go | 2 +- internal/matcher/named.go | 2 - internal/middleware/bodylimit/bodylimit.go | 2 - .../middleware/compression/compression.go | 2 +- .../compression/compression_bench_test.go | 2 +- .../middleware/compression/pool_bench_test.go | 2 +- internal/middleware/rewrite/rewrite.go | 2 +- internal/middleware/security/access.go | 2 +- internal/middleware/security/auth.go | 2 +- internal/mimeutil/detect.go | 2 +- internal/netutil/host.go | 4 -- internal/netutil/host_test.go | 2 - internal/proxy/health.go | 2 - internal/proxy/health_test.go | 4 -- internal/proxy/proxy.go | 24 +++++------ internal/proxy/proxy_bench_test.go | 2 +- internal/proxy/proxy_dns.go | 2 - internal/proxy/proxy_dns_test.go | 21 ---------- internal/proxy/proxy_test.go | 4 -- internal/proxy/tempfile_test.go | 16 -------- internal/server/purge.go | 2 - internal/server/purge_test.go | 24 ----------- internal/server/server_test.go | 1 - internal/server/start_integration_test.go | 2 +- internal/server/testutil.go | 9 ----- internal/server/testutil_test.go | 8 ---- internal/server/upgrade.go | 2 - internal/server/upgrade_test.go | 29 -------------- internal/server/vhost_test.go | 1 - internal/ssl/client_verify.go | 4 +- internal/ssl/client_verify_test.go | 30 -------------- internal/ssl/ocsp.go | 2 - internal/ssl/ocsp_test.go | 9 ----- internal/ssl/session_tickets.go | 2 - internal/ssl/session_tickets_test.go | 3 -- internal/ssl/ssl.go | 2 - internal/ssl/ssl_bench_test.go | 4 -- internal/ssl/ssl_test.go | 20 ---------- internal/stream/stream.go | 2 - internal/stream/stream_coverage_test.go | 18 --------- internal/stream/stream_test.go | 18 --------- internal/utils/httperror.go | 16 ++++---- internal/utils/internal.go | 2 - internal/utils/utils_test.go | 2 - internal/variable/builtin.go | 4 +- internal/variable/ssl.go | 20 +++++----- internal/variable/ssl_test.go | 14 ------- internal/variable/variable.go | 2 - internal/variable/variable_bench_test.go | 2 - internal/variable/variable_test.go | 32 --------------- 78 files changed, 63 insertions(+), 469 deletions(-) diff --git a/gjson/config.go b/gjson/config.go index 28f514d..960d66b 100644 --- a/gjson/config.go +++ b/gjson/config.go @@ -44,5 +44,3 @@ func defaultConfig() *Config { encodeSortKeys: defaultEncodeSortKeys, } } - - diff --git a/gjson/gjson.go b/gjson/gjson.go index 9b661da..c7b7e6d 100644 --- a/gjson/gjson.go +++ b/gjson/gjson.go @@ -77,5 +77,3 @@ func Loader(L *glua.LState) int { L.Push(mod) return 1 } - - diff --git a/internal/app/app_test.go b/internal/app/app_test.go index 17a1573..b4ada57 100644 --- a/internal/app/app_test.go +++ b/internal/app/app_test.go @@ -371,19 +371,6 @@ func TestPrintVersion(t *testing.T) { } } - - - - - - - - - - - - - // TestVersionVariables 测试版本变量默认值 func TestVersionVariables(t *testing.T) { if version.Version != "dev" { @@ -434,25 +421,6 @@ func TestAppFields(t *testing.T) { } } - - - - - - - - - - - - - - - - - - - // TestGenerateConfig_ErrorCase 测试生成配置时的错误情况 // 注意:config.GenerateConfigYAML 正常情况下不会失败, // 但我们测试文件写入失败的情况 @@ -475,14 +443,6 @@ func TestGenerateConfig_ErrorCase(t *testing.T) { }) } - - - - - - - - // TestApp_Run_WithValidConfig 测试 App.Run 加载有效配置 // 注意:此测试验证配置加载路径,但由于服务器启动会阻塞, // 我们通过子进程测试或使用 short 标志跳过完整运行 diff --git a/internal/app/testutil.go b/internal/app/testutil.go index 91b14e0..cb338c1 100644 --- a/internal/app/testutil.go +++ b/internal/app/testutil.go @@ -6,6 +6,3 @@ // // 作者:xfy package app - - - diff --git a/internal/cache/cache_test.go b/internal/cache/cache_test.go index d32c206..de5bd6e 100644 --- a/internal/cache/cache_test.go +++ b/internal/cache/cache_test.go @@ -618,5 +618,3 @@ func TestProxyCacheDeleteByPatternNoMatch(t *testing.T) { t.Error("Original entry should still exist") } } - - diff --git a/internal/config/config.go b/internal/config/config.go index 206be0b..edd932e 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -29,7 +29,7 @@ import ( // 默认配置常量。 const ( -// DefaultPprofPath pprof 端点的默认路径。 + // DefaultPprofPath pprof 端点的默认路径。 DefaultPprofPath = "/debug/pprof" ) @@ -40,13 +40,13 @@ type ServerMode string // ServerMode 枚举值。 const ( -// ServerModeSingle 单服务器模式 - 只运行一个服务器实例。 + // ServerModeSingle 单服务器模式 - 只运行一个服务器实例。 ServerModeSingle ServerMode = "single" -// ServerModeVHost 虚拟主机模式 - 多个服务器共享相同的监听地址。 + // ServerModeVHost 虚拟主机模式 - 多个服务器共享相同的监听地址。 ServerModeVHost ServerMode = "vhost" -// ServerModeMultiServer 多服务器模式 - 多个服务器监听不同的地址。 + // ServerModeMultiServer 多服务器模式 - 多个服务器监听不同的地址。 ServerModeMultiServer ServerMode = "multi_server" -// ServerModeAuto 自动模式 - 根据配置自动推断运行模式。 + // ServerModeAuto 自动模式 - 根据配置自动推断运行模式。 ServerModeAuto ServerMode = "auto" ) @@ -72,17 +72,17 @@ const ( // // 处理每个服务器配置 // } type Config struct { - Mode ServerMode `yaml:"mode"` - Variables VariablesConfig `yaml:"variables"` - Logging LoggingConfig `yaml:"logging"` - Servers []ServerConfig `yaml:"servers"` - Stream []StreamConfig `yaml:"stream"` - Monitoring MonitoringConfig `yaml:"monitoring"` - HTTP3 HTTP3Config `yaml:"http3"` - Resolver ResolverConfig `yaml:"resolver"` - Performance PerformanceConfig `yaml:"performance"` - Shutdown ShutdownConfig `yaml:"shutdown"` - Include []IncludeConfig `yaml:"include"` // 配置引入,支持从其他文件引入配置片段 + Mode ServerMode `yaml:"mode"` + Variables VariablesConfig `yaml:"variables"` + Logging LoggingConfig `yaml:"logging"` + Servers []ServerConfig `yaml:"servers"` + Stream []StreamConfig `yaml:"stream"` + Monitoring MonitoringConfig `yaml:"monitoring"` + HTTP3 HTTP3Config `yaml:"http3"` + Resolver ResolverConfig `yaml:"resolver"` + Performance PerformanceConfig `yaml:"performance"` + Shutdown ShutdownConfig `yaml:"shutdown"` + Include []IncludeConfig `yaml:"include"` // 配置引入,支持从其他文件引入配置片段 } // parseSize 解析大小字符串(支持 k, m 单位)。 diff --git a/internal/config/config_test.go b/internal/config/config_test.go index a4d76ba..866d5ba 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -134,13 +134,8 @@ servers: }) } - - - - // TestConfigMethods 测试 Config 结构体的方法。 - func TestProxyBufferingConfig_ParseBuffers(t *testing.T) { tests := []struct { name string diff --git a/internal/config/defaults_test.go b/internal/config/defaults_test.go index adf9f18..f7d521a 100644 --- a/internal/config/defaults_test.go +++ b/internal/config/defaults_test.go @@ -253,5 +253,3 @@ func TestGenerateConfigYAMLContainsAllSections(t *testing.T) { } } } - - diff --git a/internal/handler/static_test.go b/internal/handler/static_test.go index 82b3fda..8ff306b 100644 --- a/internal/handler/static_test.go +++ b/internal/handler/static_test.go @@ -1260,8 +1260,8 @@ func TestStaticHandler_AliasVsRoot(t *testing.T) { wantContent: "from root", // /var/www/images/logo.png }, { - name: "alias 模式:请求路径替换匹配部分", - handler: &StaticHandler{ + name: "alias 模式:请求路径替换匹配部分", + handler: &StaticHandler{ alias: aliasDir, pathPrefix: "/images/", pathPrefixLen: len("/images/"), diff --git a/internal/http2/adapter.go b/internal/http2/adapter.go index 481e550..84218ac 100644 --- a/internal/http2/adapter.go +++ b/internal/http2/adapter.go @@ -202,5 +202,3 @@ func (a *FastHTTPHandlerAdapter) convertResponse(ctx *fasthttp.RequestCtx, w htt } } } - - diff --git a/internal/http2/integration_tls_test.go b/internal/http2/integration_tls_test.go index 415810c..bd46c26 100644 --- a/internal/http2/integration_tls_test.go +++ b/internal/http2/integration_tls_test.go @@ -205,7 +205,6 @@ func TestTLSHandshakeFailure(t *testing.T) { // TestALPNNegotiationH2 测试 ALPN 协商选择 h2。 - // TestALPNHTTP11Fallback 测试 ALPN 协商回退到 HTTP/1.1。 func TestALPNHTTP11Fallback(t *testing.T) { cert, _ := generateTestCert(t) @@ -270,10 +269,8 @@ func TestALPNHTTP11Fallback(t *testing.T) { // TestTLSListenerWrapper 测试 TLS 监听器包装。 - // TestTLSListenerExistingProtos 测试已有 NextProtos 的情况。 - // TestServeHTTP1Fallback 测试 HTTP/1.1 回退。 func TestServeHTTP1Fallback(t *testing.T) { handler := func(ctx *fasthttp.RequestCtx) { @@ -375,6 +372,3 @@ func (m *mockTestConn) SetReadDeadline(_ time.Time) error { return nil } func (m *mockTestConn) SetWriteDeadline(_ time.Time) error { return nil } - - - diff --git a/internal/http2/server.go b/internal/http2/server.go index 2615928..63b0773 100644 --- a/internal/http2/server.go +++ b/internal/http2/server.go @@ -329,5 +329,3 @@ func (p *connectionPool) closeAll() { } p.conns = make(map[string][]net.Conn) } - - diff --git a/internal/http2/server_bench_test.go b/internal/http2/server_bench_test.go index 806a68a..97cafb4 100644 --- a/internal/http2/server_bench_test.go +++ b/internal/http2/server_bench_test.go @@ -420,7 +420,6 @@ func BenchmarkHTTP2RequestRoundTrip_WithBody_Parallel(b *testing.B) { // 测量 ValidateSettings 函数的开销,用于了解 // 配置验证阶段的性能成本。 - // BenchmarkHTTP2AdapterWithHPACKHeaders 测试带 HPACK 编码头部的适配器性能 // // 模拟 HTTP/2 场景下经过 HPACK 压缩和解压缩后的头部转换开销。 diff --git a/internal/http3/adapter.go b/internal/http3/adapter.go index 57d50ff..4c86701 100644 --- a/internal/http3/adapter.go +++ b/internal/http3/adapter.go @@ -148,5 +148,3 @@ func (a *Adapter) convertResponse(ctx *fasthttp.RequestCtx, w http.ResponseWrite _, _ = w.Write(body) } } - - diff --git a/internal/http3/server.go b/internal/http3/server.go index abc0997..40f1384 100644 --- a/internal/http3/server.go +++ b/internal/http3/server.go @@ -208,5 +208,3 @@ func (s *Server) Stop() error { logging.Info().Msg("HTTP/3 server stopped") return nil } - - diff --git a/internal/http3/server_test.go b/internal/http3/server_test.go index 0b64354..d57cda9 100644 --- a/internal/http3/server_test.go +++ b/internal/http3/server_test.go @@ -122,8 +122,4 @@ func TestNewServer_Success(t *testing.T) { // TestStart_AlreadyRunning 测试启动已运行的服务器 - // TestStart_InvalidListenAddress 测试无效监听地址 - - - diff --git a/internal/integration/e2e_bench_test.go b/internal/integration/e2e_bench_test.go index 616e86c..3d12e0c 100644 --- a/internal/integration/e2e_bench_test.go +++ b/internal/integration/e2e_bench_test.go @@ -31,7 +31,6 @@ import ( "github.com/valyala/fasthttp" "github.com/valyala/fasthttp/fasthttputil" - "rua.plus/lolly/internal/testutil" "rua.plus/lolly/internal/cache" "rua.plus/lolly/internal/config" "rua.plus/lolly/internal/handler" @@ -43,6 +42,7 @@ import ( "rua.plus/lolly/internal/middleware/rewrite" "rua.plus/lolly/internal/middleware/security" "rua.plus/lolly/internal/proxy" + "rua.plus/lolly/internal/testutil" ) // generateTestCert 生成自签名测试证书(服务器认证)。 @@ -1446,8 +1446,8 @@ func BenchmarkE2EBasicAuth(b *testing.B) { } warmupProxy(p, "/api/test", 5) - // 创建 Basic Auth 中间件(使用 bcrypt 哈希) - bcryptPassword := "$2a$10$BOx2i1WZ6iFADhBylIiAAOe3OgG2tQ1dkhgLhJCNnm9beidTgqMq." + // 创建 Basic Auth 中间件(使用 bcrypt 哈希) + bcryptPassword := "$2a$10$BOx2i1WZ6iFADhBylIiAAOe3OgG2tQ1dkhgLhJCNnm9beidTgqMq." auth, err := security.NewBasicAuth(&config.AuthConfig{ Type: "basic", RequireTLS: false, diff --git a/internal/loadbalance/slow_start.go b/internal/loadbalance/slow_start.go index 2919100..1aebf21 100644 --- a/internal/loadbalance/slow_start.go +++ b/internal/loadbalance/slow_start.go @@ -159,5 +159,3 @@ func (m *SlowStartManager) updateEffectiveWeights() { } } } - - diff --git a/internal/loadbalance/slow_start_test.go b/internal/loadbalance/slow_start_test.go index 1ebc46c..e134186 100644 --- a/internal/loadbalance/slow_start_test.go +++ b/internal/loadbalance/slow_start_test.go @@ -43,5 +43,3 @@ func TestTarget_GetEffectiveWeight(t *testing.T) { }) } } - - diff --git a/internal/lua/api_location.go b/internal/lua/api_location.go index f191fc2..c0dc1c8 100644 --- a/internal/lua/api_location.go +++ b/internal/lua/api_location.go @@ -257,5 +257,3 @@ func headersToLuaTable(L *glua.LState, headers map[string]string) *glua.LTable { } return table } - - diff --git a/internal/lua/api_log.go b/internal/lua/api_log.go index 43f784f..ece7112 100644 --- a/internal/lua/api_log.go +++ b/internal/lua/api_log.go @@ -26,7 +26,7 @@ import ( // 日志级别常量(与 OpenResty/ngx_lua 兼容) const ( -// LogStderr 标准错误日志级别。 + // LogStderr 标准错误日志级别。 LogStderr = 0 // LogEmerg 紧急日志级别。 LogEmerg = 1 @@ -48,7 +48,7 @@ const ( // HTTP 状态码常量 const ( -// HTTPContinue HTTP 100 继续状态码。 + // HTTPContinue HTTP 100 继续状态码。 HTTPContinue = 100 // HTTPSwitchingProtocols HTTP 101 切换协议状态码。 HTTPSwitchingProtocols = 101 @@ -390,5 +390,3 @@ func (api *ngxLogAPI) luaRedirect(L *glua.LState) int { L.RaiseError("%s", "ngx.redirect: "+uri) return 0 } - - diff --git a/internal/lua/api_req.go b/internal/lua/api_req.go index 3765a59..48ec1ae 100644 --- a/internal/lua/api_req.go +++ b/internal/lua/api_req.go @@ -593,5 +593,3 @@ func (api *ngxReqAPI) GetPerformanceRatio() float64 { func (api *ngxReqAPI) ResetMetrics() { api.metrics = ngxReqMetrics{} } - - diff --git a/internal/lua/api_resp.go b/internal/lua/api_resp.go index d53803d..27be61f 100644 --- a/internal/lua/api_resp.go +++ b/internal/lua/api_resp.go @@ -197,5 +197,3 @@ func (api *ngxRespAPI) SetHeader(name, value string) { api.headersCache = nil api.headersCacheOnce = sync.Once{} } - - diff --git a/internal/lua/api_var.go b/internal/lua/api_var.go index 7e5a0d2..0a9bc00 100644 --- a/internal/lua/api_var.go +++ b/internal/lua/api_var.go @@ -261,5 +261,3 @@ func (api *ngxVarAPI) GetVariable(name string) (string, bool) { value := api.getVariable(name) return value, value != "" } - - diff --git a/internal/lua/middleware_config.go b/internal/lua/middleware_config.go index 45d332e..76f4e0b 100644 --- a/internal/lua/middleware_config.go +++ b/internal/lua/middleware_config.go @@ -90,5 +90,3 @@ func ParsePhase(s string) (Phase, error) { return PhaseInit, fmt.Errorf("unknown phase: %s", s) } } - - diff --git a/internal/lua/register.go b/internal/lua/register.go index 31a6956..7ae292c 100644 --- a/internal/lua/register.go +++ b/internal/lua/register.go @@ -21,5 +21,3 @@ type APIMethod struct { // Func Lua 函数实现 Func func(*glua.LState) int } - - diff --git a/internal/matcher/location.go b/internal/matcher/location.go index e3c1582..89cffc2 100644 --- a/internal/matcher/location.go +++ b/internal/matcher/location.go @@ -263,5 +263,3 @@ func (e *LocationEngine) checkConflict(path, locationType string) error { e.registeredPaths[path] = locationType return nil } - - diff --git a/internal/matcher/location_test.go b/internal/matcher/location_test.go index fe5a8f9..948ec2b 100644 --- a/internal/matcher/location_test.go +++ b/internal/matcher/location_test.go @@ -337,7 +337,3 @@ func TestLocationEngine_MarkInitialized(t *testing.T) { t.Error("AddNamed should fail after initialized") } } - - - - diff --git a/internal/matcher/matcher.go b/internal/matcher/matcher.go index 324094f..efaaa81 100644 --- a/internal/matcher/matcher.go +++ b/internal/matcher/matcher.go @@ -24,7 +24,7 @@ import "github.com/valyala/fasthttp" // LocationType 常量定义,表示不同 location 匹配类型。 const ( -// LocationTypeExact 精确匹配类型(=)。 + // LocationTypeExact 精确匹配类型(=)。 LocationTypeExact = "exact" // LocationTypePrefix 前缀匹配类型。 LocationTypePrefix = "prefix" diff --git a/internal/matcher/named.go b/internal/matcher/named.go index 363a32b..84d4a32 100644 --- a/internal/matcher/named.go +++ b/internal/matcher/named.go @@ -33,5 +33,3 @@ func NewNamedMatcher(name string, handler fasthttp.RequestHandler) *NamedMatcher handler: handler, } } - - diff --git a/internal/middleware/bodylimit/bodylimit.go b/internal/middleware/bodylimit/bodylimit.go index 73632e4..f1f1684 100644 --- a/internal/middleware/bodylimit/bodylimit.go +++ b/internal/middleware/bodylimit/bodylimit.go @@ -275,5 +275,3 @@ func ParseSize(sizeStr string) (int64, error) { return int64(value * multiplier), nil } - - diff --git a/internal/middleware/compression/compression.go b/internal/middleware/compression/compression.go index 1f20b92..c56955e 100644 --- a/internal/middleware/compression/compression.go +++ b/internal/middleware/compression/compression.go @@ -96,7 +96,7 @@ const streamingThreshold = 64 * 1024 // 64KB type Algorithm int const ( -// AlgorithmGzip 使用 gzip 压缩算法。 + // AlgorithmGzip 使用 gzip 压缩算法。 AlgorithmGzip Algorithm = iota // AlgorithmBrotli 使用 brotli 压缩算法。 AlgorithmBrotli diff --git a/internal/middleware/compression/compression_bench_test.go b/internal/middleware/compression/compression_bench_test.go index 2d346d8..057715b 100644 --- a/internal/middleware/compression/compression_bench_test.go +++ b/internal/middleware/compression/compression_bench_test.go @@ -9,8 +9,8 @@ import ( "testing" "github.com/valyala/fasthttp" - "rua.plus/lolly/internal/testutil" "rua.plus/lolly/internal/config" + "rua.plus/lolly/internal/testutil" ) // BenchmarkGzipCompress_1KB 测试 gzip 压缩 1KB 数据的性能。 diff --git a/internal/middleware/compression/pool_bench_test.go b/internal/middleware/compression/pool_bench_test.go index 88f05bb..050809d 100644 --- a/internal/middleware/compression/pool_bench_test.go +++ b/internal/middleware/compression/pool_bench_test.go @@ -18,8 +18,8 @@ import ( "testing" "github.com/valyala/fasthttp" - "rua.plus/lolly/internal/testutil" "rua.plus/lolly/internal/config" + "rua.plus/lolly/internal/testutil" ) // BenchmarkGzipPool_GetPut 测试 gzip.Writer 池直接操作。 diff --git a/internal/middleware/rewrite/rewrite.go b/internal/middleware/rewrite/rewrite.go index 8501650..027542c 100644 --- a/internal/middleware/rewrite/rewrite.go +++ b/internal/middleware/rewrite/rewrite.go @@ -36,7 +36,7 @@ const MaxRewriteIterations = 10 type Flag int const ( -// FlagLast 继续匹配其他规则(nginx 行为:重新从第一条规则开始匹配)。 + // FlagLast 继续匹配其他规则(nginx 行为:重新从第一条规则开始匹配)。 // 匹配到规则后会重新从第一条规则开始遍历,用于多规则链式重写。 FlagLast Flag = iota // FlagRedirect 返回 302 临时重定向。 diff --git a/internal/middleware/security/access.go b/internal/middleware/security/access.go index 7679030..b8ec439 100644 --- a/internal/middleware/security/access.go +++ b/internal/middleware/security/access.go @@ -43,7 +43,7 @@ import ( type Action int const ( -// ActionAllow 允许请求通过。 + // ActionAllow 允许请求通过。 ActionAllow Action = iota // ActionDeny 拒绝请求(返回 403 Forbidden)。 ActionDeny diff --git a/internal/middleware/security/auth.go b/internal/middleware/security/auth.go index 25913b7..4086157 100644 --- a/internal/middleware/security/auth.go +++ b/internal/middleware/security/auth.go @@ -47,7 +47,7 @@ import ( type HashAlgorithm int const ( -// HashBcrypt bcrypt 哈希算法(默认,推荐)。 + // HashBcrypt bcrypt 哈希算法(默认,推荐)。 HashBcrypt HashAlgorithm = iota // HashArgon2id Argon2id 哈希算法(更安全,计算密集)。 HashArgon2id diff --git a/internal/mimeutil/detect.go b/internal/mimeutil/detect.go index e4f6256..c1c9071 100644 --- a/internal/mimeutil/detect.go +++ b/internal/mimeutil/detect.go @@ -102,7 +102,7 @@ func SetDefaultType(defaultType string) { // - filePath: 文件路径 // // 返回值: -// - string: MIME 类型,未知类型返回 defaultMIME(默认为 application/octet-stream) +// - string: MIME 类型,未知类型返回 defaultMIME(默认为 application/octet-stream) func DetectContentType(filePath string) string { ext := strings.ToLower(filepath.Ext(filePath)) diff --git a/internal/netutil/host.go b/internal/netutil/host.go index 92984ff..03aa481 100644 --- a/internal/netutil/host.go +++ b/internal/netutil/host.go @@ -5,8 +5,6 @@ // 作者:xfy package netutil - - // StripPort 从 Host 头中移除端口号。 // // 支持 IPv4 和 IPv6 格式: @@ -44,5 +42,3 @@ func StripPort(host string) string { return host } - - diff --git a/internal/netutil/host_test.go b/internal/netutil/host_test.go index bafcbea..462406c 100644 --- a/internal/netutil/host_test.go +++ b/internal/netutil/host_test.go @@ -35,5 +35,3 @@ func TestStripPort(t *testing.T) { }) } } - - diff --git a/internal/proxy/health.go b/internal/proxy/health.go index d545d4e..d962761 100644 --- a/internal/proxy/health.go +++ b/internal/proxy/health.go @@ -278,5 +278,3 @@ func (h *HealthChecker) MarkHealthy(target *loadbalance.Target) { h.slowStartManager.OnTargetHealthy(target) } } - - diff --git a/internal/proxy/health_test.go b/internal/proxy/health_test.go index 0a703d9..0b08730 100644 --- a/internal/proxy/health_test.go +++ b/internal/proxy/health_test.go @@ -25,10 +25,6 @@ import ( "rua.plus/lolly/internal/loadbalance" ) - - - - // TestCheckTarget 测试 checkTarget 方法。 func TestCheckTarget(t *testing.T) { t.Run("健康响应", func(t *testing.T) { diff --git a/internal/proxy/proxy.go b/internal/proxy/proxy.go index 95a47e3..cd1c10d 100644 --- a/internal/proxy/proxy.go +++ b/internal/proxy/proxy.go @@ -673,17 +673,17 @@ func (p *Proxy) ServeHTTP(ctx *fasthttp.RequestCtx) { } return } - // 过期缓存,尝试后台刷新,同时返回旧数据 - if !p.config.Cache.BackgroundUpdateDisable { - entry.Updating.Store(true) - reqCopy := fasthttp.AcquireRequest() - ctx.Request.CopyTo(reqCopy) - go func() { - defer entry.Updating.Store(false) - defer fasthttp.ReleaseRequest(reqCopy) - p.backgroundRefresh(reqCopy, target, hashKey, origKey) - }() - } + // 过期缓存,尝试后台刷新,同时返回旧数据 + if !p.config.Cache.BackgroundUpdateDisable { + entry.Updating.Store(true) + reqCopy := fasthttp.AcquireRequest() + ctx.Request.CopyTo(reqCopy) + go func() { + defer entry.Updating.Store(false) + defer fasthttp.ReleaseRequest(reqCopy) + p.backgroundRefresh(reqCopy, target, hashKey, origKey) + }() + } upstreamAddr = upstreamCache upstreamStatus = entry.Status @@ -990,5 +990,3 @@ func isWebSocketRequest(ctx *fasthttp.RequestCtx) bool { upgrade := ctx.Request.Header.Peek("Upgrade") return strings.EqualFold(string(upgrade), "websocket") } - - diff --git a/internal/proxy/proxy_bench_test.go b/internal/proxy/proxy_bench_test.go index fdd77ac..f8e60c8 100644 --- a/internal/proxy/proxy_bench_test.go +++ b/internal/proxy/proxy_bench_test.go @@ -9,9 +9,9 @@ import ( "github.com/valyala/fasthttp" "github.com/valyala/fasthttp/fasthttputil" - "rua.plus/lolly/internal/testutil" "rua.plus/lolly/internal/config" "rua.plus/lolly/internal/loadbalance" + "rua.plus/lolly/internal/testutil" "rua.plus/lolly/internal/variable" ) diff --git a/internal/proxy/proxy_dns.go b/internal/proxy/proxy_dns.go index ea3e9b2..2ff1ae0 100644 --- a/internal/proxy/proxy_dns.go +++ b/internal/proxy/proxy_dns.go @@ -193,5 +193,3 @@ func (p *Proxy) getResolverTTL() time.Duration { // 这里返回默认值 return 30 * time.Second } - - diff --git a/internal/proxy/proxy_dns_test.go b/internal/proxy/proxy_dns_test.go index 6a6ae8e..a522cfc 100644 --- a/internal/proxy/proxy_dns_test.go +++ b/internal/proxy/proxy_dns_test.go @@ -120,66 +120,45 @@ func TestSetResolver(t *testing.T) { // TestGetResolverStats_NoResolver 测试没有解析器时返回空统计。 - // TestGetResolverStats_WithResolver 测试有解析器时返回统计。 - // TestStartWithResolver 测试启动代理时解析器正确启动。 - // TestStartResolverFails 测试解析器启动失败时代理返回错误。 - // TestStartIdempotent 测试 Start 是幂等的。 - // TestStopIdempotent 测试 Stop 是幂等的。 - // TestStopWithoutResolver 测试没有解析器时停止代理。 - // TestRefreshDNS_Success 测试 DNS 刷新成功场景。 - // TestRefreshDNS_LookupError 测试 DNS 刷新时查找失败场景。 - // TestRefreshDNS_NoResolver 测试没有解析器时刷新不执行任何操作。 - // TestRefreshDNS_IPAddressTarget 测试 IP 类型的目标不需要解析。 - // TestRefreshDNS_RecentlyResolved 测试最近已解析的目标不需要再次解析。 - // TestRefreshDNS_ExpiredResolve 测试 TTL 过期后需要重新解析。 // 该测试验证 TTL 过期检查的正确性: // - 短时间内(< TTL)不需要重新解析 // - 长时间后(> TTL)需要重新解析 - // TestUpdateHostClientAddr_HTTP 测试 HTTP 目标地址更新。 - // TestUpdateHostClientAddr_HTTPS 测试 HTTPS 目标地址更新。 - // TestUpdateHostClientAddr_DefaultPort 测试没有端口时使用默认端口。 - // TestUpdateHostClientAddr_NonExistentTarget 测试不存在的目标不更新。 - // TestGetResolverTTL 测试 TTL 获取。 - // TestDNSRefreshLoop_StartStop 测试 DNS 刷新循环的启动和停止。 - // TestMultipleTargets_Refresh 测试多目标刷新。 - // TestStopResolverFails 测试停止解析器失败时返回错误。 - diff --git a/internal/proxy/proxy_test.go b/internal/proxy/proxy_test.go index 31ecb8e..5299804 100644 --- a/internal/proxy/proxy_test.go +++ b/internal/proxy/proxy_test.go @@ -574,13 +574,10 @@ func TestGetClientIP(t *testing.T) { // TestUpdateTargets 测试更新目标 - // TestGetTargets 测试获取目标列表 - // TestGetConfig 测试获取配置 - // TestIsWebSocketRequest 测试WebSocket请求检测 func TestIsWebSocketRequest(t *testing.T) { tests := []struct { @@ -840,7 +837,6 @@ func TestGetClient(t *testing.T) { // TestProxyCache 测试代理缓存功能 - // TestServeHTTP_WithPassiveHealthCheck 测试带有被动健康检查的请求转发 func TestServeHTTP_WithPassiveHealthCheck(t *testing.T) { cfg := &config.ProxyConfig{ diff --git a/internal/proxy/tempfile_test.go b/internal/proxy/tempfile_test.go index 7577872..b825e45 100644 --- a/internal/proxy/tempfile_test.go +++ b/internal/proxy/tempfile_test.go @@ -11,32 +11,16 @@ // 作者:xfy package proxy - - - // TestTempFileManager_ShouldUseTempFile 测试阈值判定 - // TestTempFile_Write 测试临时文件写入 - // TestTempFile_WriteTo 测试临时文件写入响应 - // TestTempFile_Close 测试临时文件关闭和清理 - - - // TestGetDefaultTempFileManager 测试默认临时文件管理器 - - - // TestGlobalTempFileCleaner 测试全局临时文件清理器 - // strContains 检查字符串是否包含子串 - - - diff --git a/internal/server/purge.go b/internal/server/purge.go index 3635d3b..c86f8a9 100644 --- a/internal/server/purge.go +++ b/internal/server/purge.go @@ -150,5 +150,3 @@ func (h *PurgeHandler) purgeByPattern(pattern string, method string) int { return deleted } - - diff --git a/internal/server/purge_test.go b/internal/server/purge_test.go index f901b16..4301fab 100644 --- a/internal/server/purge_test.go +++ b/internal/server/purge_test.go @@ -596,10 +596,6 @@ func TestPurgeHandler_SendError(t *testing.T) { } } - - - - // TestPurgeHandler_CacheKeyWithMethod 测试带方法的缓存键。 func TestPurgeHandler_CacheKeyWithMethod(t *testing.T) { tests := []struct { @@ -664,10 +660,6 @@ func TestPurgeHandler_checkAccess_NilContext(t *testing.T) { }) } - - - - // TestPurgeHandler_ServeHTTP_WithAllowList 测试带白名单的请求处理。 func TestPurgeHandler_ServeHTTP_WithAllowList(t *testing.T) { cfg := &config.CacheAPIConfig{ @@ -719,18 +711,6 @@ func TestPurgeHandler_checkAccess_WithAllowedIP(t *testing.T) { }) } - - - - - - - - - - - - // TestPurgeHandler_PurgeByPath_HashConsistency 测试哈希一致性。 func TestPurgeHandler_PurgeByPath_HashConsistency(t *testing.T) { // 验证相同路径和方法产生相同哈希 @@ -803,7 +783,3 @@ func TestPurgeHandler_PurgeByPattern_PatternMatching(t *testing.T) { }) } } - - - - diff --git a/internal/server/server_test.go b/internal/server/server_test.go index 9cf7300..5f95551 100644 --- a/internal/server/server_test.go +++ b/internal/server/server_test.go @@ -1221,7 +1221,6 @@ func TestServer_SetUpgradeManager(t *testing.T) { // TestServer_GetResolver 测试获取解析器。 - // TestServer_StopWithTimeout_WithListeners 测试带监听器的停止。 func TestServer_StopWithTimeout_WithListeners(t *testing.T) { cfg := &config.Config{ diff --git a/internal/server/start_integration_test.go b/internal/server/start_integration_test.go index 20b1c60..3453eb3 100644 --- a/internal/server/start_integration_test.go +++ b/internal/server/start_integration_test.go @@ -20,8 +20,8 @@ import ( "time" "github.com/valyala/fasthttp" - "rua.plus/lolly/internal/testutil" "rua.plus/lolly/internal/config" + "rua.plus/lolly/internal/testutil" ) // TestStart_Integration 测试完整的服务器启动和请求处理流程 diff --git a/internal/server/testutil.go b/internal/server/testutil.go index 2515ed4..a770181 100644 --- a/internal/server/testutil.go +++ b/internal/server/testutil.go @@ -28,9 +28,6 @@ type MockFastServer struct { CloseOnShutdown bool } - - - // TestDependencies 包含测试时可注入的依赖 // 使用具体指针类型,允许注入 Mock 实现 type TestDependencies struct { @@ -38,8 +35,6 @@ type TestDependencies struct { TLSManager *ssl.TLSManager } - - // TestServerOptions 测试服务器的可选配置 type TestServerOptions struct { MockFastServer *MockFastServer @@ -47,7 +42,3 @@ type TestServerOptions struct { SkipListener bool DisableMiddleware bool } - - - - diff --git a/internal/server/testutil_test.go b/internal/server/testutil_test.go index 8ea6211..66f97bd 100644 --- a/internal/server/testutil_test.go +++ b/internal/server/testutil_test.go @@ -8,28 +8,20 @@ import ( // TestMockFastServer_Serve 测试 MockFastServer.Serve 方法 - // TestMockFastServer_ServeTLS 测试 MockFastServer.ServeTLS 方法 - // TestMockFastServer_Shutdown 测试 MockFastServer.Shutdown 方法 - // TestNewServerForTesting 测试 NewServerForTesting 函数 - // TestNewTestServerWithOptions 测试 NewTestServerWithOptions 函数 - // TestMustStartTestServer 测试 MustStartTestServer 函数 - // TestTestDependencies 测试 TestDependencies 结构体 - // TestTestServerOptions 测试 TestServerOptions 结构体 - // TestMockFastServer_Fields 测试 MockFastServer 字段 func TestMockFastServer_Fields(t *testing.T) { mock := &MockFastServer{ diff --git a/internal/server/upgrade.go b/internal/server/upgrade.go index fc692e1..b7c8865 100644 --- a/internal/server/upgrade.go +++ b/internal/server/upgrade.go @@ -236,5 +236,3 @@ func listenerFile(listener net.Listener) (*os.File, error) { return nil, fmt.Errorf("unsupported listener type: %T", listener) } } - - diff --git a/internal/server/upgrade_test.go b/internal/server/upgrade_test.go index aa44fe6..fe45e02 100644 --- a/internal/server/upgrade_test.go +++ b/internal/server/upgrade_test.go @@ -47,10 +47,6 @@ func TestIsChild(t *testing.T) { } } - - - - func TestGetInheritedListenersNoFds(t *testing.T) { mgr := NewUpgradeManager(nil) @@ -64,10 +60,6 @@ func TestGetInheritedListenersNoFds(t *testing.T) { } } - - - - // TestUpgradeSetListeners 测试监听器设置 func TestUpgradeSetListeners(t *testing.T) { mgr := NewUpgradeManager(nil) @@ -110,7 +102,6 @@ func TestWritePid_NoPidFile(t *testing.T) { // TestReadOldPid_InvalidContent 测试 PID 文件内容无效时的错误处理 - // TestGetInheritedListeners_InvalidFds 测试 LISTEN_FDS 环境变量格式无效 func TestGetInheritedListeners_InvalidFds(t *testing.T) { tests := []struct { @@ -155,7 +146,6 @@ func TestGetInheritedListeners_InvalidFds(t *testing.T) { // TestWaitForShutdown_WithTimeout 测试超时行为 - // TestListenerFile_TCPListener 测试从 TCP 监听器获取文件 func TestListenerFile_TCPListener(t *testing.T) { listener, err := net.Listen("tcp", "127.0.0.1:0") @@ -211,49 +201,35 @@ func TestGracefulUpgrade_NoListeners(t *testing.T) { // TestNotifyOldProcess_WithCurrentPid 测试通知进程 // 注意:不能向当前进程发送 SIGQUIT,会导致测试崩溃 - // TestReadOldPid_EmptyFile 测试空 PID 文件 - // TestNotifyOldProcess_ReadPidError 测试读取 PID 失败的情况 - // TestNotifyOldProcess_ZeroPid 测试 PID 为 0 的情况 - // TestNotifyOldProcess_NonExistentProcess 测试通知不存在的进程 - // TestNotifyOldProcess_FindProcessError 测试 os.FindProcess 的行为 // 注意:在 Unix 系统上,os.FindProcess 总是成功,即使进程不存在 - // TestSetupSignalHandlers_SetsUpChannel 测试信号处理器设置 - // TestSetupSignalHandlers_TriggersUpgrade 测试信号触发升级 - // TestGracefulUpgrade_UnsupportedListener 测试不支持的监听器类型 - // TestGracefulUpgrade_NonexistentBinary 测试不存在的二进制文件 // 注意:此测试使用 mock 监听器避免创建实际网络连接 - // TestGracefulUpgrade_WithPidFile 测试升级时写入 PID 文件 // 注意:此测试使用 mock 监听器避免创建实际网络连接 - // TestWaitForShutdown_ProcessExits 测试进程退出后的等待 - // TestWaitForShutdown_Timeout 测试等待超时 - // TestWaitForShutdown_SetsOldPid 测试 oldPid 设置 - // TestListenerFile_UnixListener 测试 Unix 监听器获取文件 // 注意:跳过此测试,因为在大量测试运行时可能导致 FD 问题 func TestListenerFile_UnixListener(t *testing.T) { @@ -263,14 +239,11 @@ func TestListenerFile_UnixListener(t *testing.T) { // TestGracefulUpgrade_MultipleListeners 测试多个监听器的升级 // 注意:使用 mock 监听器避免 FD 问题 - // TestGracefulUpgrade_RelativePath 测试相对路径的二进制文件 // 注意:使用 mock 监听器避免 FD 问题 - // TestWaitForShutdown_FindProcessError 测试 FindProcess 行为 - // TestGetInheritedListeners_EnvPreserved 测试环境变量处理 func TestGetInheritedListeners_EnvPreserved(t *testing.T) { t.Setenv("LISTEN_FDS", "1") @@ -286,5 +259,3 @@ func TestGetInheritedListeners_EnvPreserved(t *testing.T) { t.Error("LISTEN_FDS env should be preserved") } } - - diff --git a/internal/server/vhost_test.go b/internal/server/vhost_test.go index 18045be..394833b 100644 --- a/internal/server/vhost_test.go +++ b/internal/server/vhost_test.go @@ -1397,7 +1397,6 @@ func TestStartVHostMode_ModeDetection(t *testing.T) { // TestStartVHostMode_StartIntegration 测试 startVHostMode 启动集成。 - // TestStartVHostMode_VHostManagerCreation 测试 VHostManager 创建逻辑。 func TestStartVHostMode_VHostManagerCreation(t *testing.T) { manager := NewVHostManager() diff --git a/internal/ssl/client_verify.go b/internal/ssl/client_verify.go index a6b0f18..2f738f3 100644 --- a/internal/ssl/client_verify.go +++ b/internal/ssl/client_verify.go @@ -29,7 +29,7 @@ import ( type ClientVerifyMode int const ( -// VerifyOff 不验证客户端证书。 + // VerifyOff 不验证客户端证书。 VerifyOff ClientVerifyMode = iota // VerifyOn 强制验证客户端证书。 VerifyOn @@ -256,5 +256,3 @@ type ClientCertInfo struct { DNSNames []string Email []string } - - diff --git a/internal/ssl/client_verify_test.go b/internal/ssl/client_verify_test.go index 3528660..d65ea90 100644 --- a/internal/ssl/client_verify_test.go +++ b/internal/ssl/client_verify_test.go @@ -132,8 +132,6 @@ func TestParseVerifyMode(t *testing.T) { } } - - // TestLoadCACertPool 测试 CA 证书池加载。 func TestLoadCACertPool(t *testing.T) { // 创建临时 CA 文件 @@ -171,10 +169,6 @@ func TestLoadCACertPool(t *testing.T) { } } - - - - // TestClientVerifier_ConfigureTLS 测试 TLS 配置。 func TestClientVerifier_ConfigureTLS(t *testing.T) { // 创建临时 CA 文件 @@ -225,12 +219,6 @@ func TestClientVerifier_ConfigureTLS_Disabled(t *testing.T) { } } - - - - - - // generateTestCRL 生成测试 CRL。 func generateTestCRL(t *testing.T, caCert *x509.Certificate, caKey *rsa.PrivateKey, revokedSerials []*big.Int) []byte { t.Helper() @@ -304,12 +292,6 @@ func TestLoadCRL(t *testing.T) { } } - - - - - - // TestVerifyConnection 测试连接验证。 func TestVerifyConnection(t *testing.T) { // 生成测试 CA 和证书 @@ -432,12 +414,6 @@ func BenchmarkLoadCACertPool(b *testing.B) { } } - - - - - - // TestNewClientVerifier_InvalidMode 测试无效验证模式。 func TestNewClientVerifier_InvalidMode(t *testing.T) { _, err := NewClientVerifier(config.ClientVerifyConfig{ @@ -449,8 +425,6 @@ func TestNewClientVerifier_InvalidMode(t *testing.T) { } } - - // TestNewClientVerifier_InvalidCRL 测试无效 CRL 文件。 func TestNewClientVerifier_InvalidCRL(t *testing.T) { tempDir := t.TempDir() @@ -475,7 +449,3 @@ func TestNewClientVerifier_InvalidCRL(t *testing.T) { t.Error("Expected error for invalid CRL file") } } - - - - diff --git a/internal/ssl/ocsp.go b/internal/ssl/ocsp.go index a752ccf..70543ce 100644 --- a/internal/ssl/ocsp.go +++ b/internal/ssl/ocsp.go @@ -425,5 +425,3 @@ func (m *OCSPManager) GetOCSPResponse(serial string) []byte { return nil } } - - diff --git a/internal/ssl/ocsp_test.go b/internal/ssl/ocsp_test.go index 44da9a0..7aa8cf9 100644 --- a/internal/ssl/ocsp_test.go +++ b/internal/ssl/ocsp_test.go @@ -129,8 +129,6 @@ func TestOCSPGetOCSPResponse(t *testing.T) { } } - - func TestOCSPStaleResponse(t *testing.T) { mgr := NewOCSPManager(nil) @@ -215,8 +213,6 @@ func TestTLSManagerWithOCSPDisabled(t *testing.T) { manager.Close() } - - func TestTLSManagerClose(t *testing.T) { tmpDir := t.TempDir() certPath := filepath.Join(tmpDir, "cert.pem") @@ -373,8 +369,6 @@ func TestOCSPConfigDefaults(t *testing.T) { } } - - // TestOCSPManager_refreshAll 测试刷新所有响应 func TestOCSPManager_refreshAll(_ *testing.T) { cfg := &OCSPConfig{ @@ -413,7 +407,6 @@ func TestOCSPManager_refreshAll(_ *testing.T) { // TestOCSPManager_GetStatus_EdgeCases 测试 GetStatus 边界情况 - // TestOCSPManager_RegisterCertificate_NilCert 测试注册空证书 func TestOCSPManager_RegisterCertificate_NilCert(t *testing.T) { mgr := NewOCSPManager(nil) @@ -494,10 +487,8 @@ func TestOCSPManager_SendOCSPRequest_Error(t *testing.T) { // TestOCSPManager_RefreshResponse_WithExistingEntry 测试刷新已有条目的响应 - // TestOCSPManager_RefreshResponse_StatusFailed 测试刷新失败后状态变化 - // TestOCSPManager_FetchOCSP_NoServer 测试无 OCSP 服务器时的 fetchOCSP func TestOCSPManager_FetchOCSP_NoServer(t *testing.T) { mgr := NewOCSPManager(nil) diff --git a/internal/ssl/session_tickets.go b/internal/ssl/session_tickets.go index 6c4218f..47742ca 100644 --- a/internal/ssl/session_tickets.go +++ b/internal/ssl/session_tickets.go @@ -379,5 +379,3 @@ type SessionTicketStatus struct { // Started 管理器是否已启动 Started bool } - - diff --git a/internal/ssl/session_tickets_test.go b/internal/ssl/session_tickets_test.go index 2b7990e..f19902a 100644 --- a/internal/ssl/session_tickets_test.go +++ b/internal/ssl/session_tickets_test.go @@ -267,10 +267,8 @@ func TestSessionTicketManager_ApplyToTLSConfig(t *testing.T) { // TestSessionTicketManager_StartStop 测试启动和停止。 - // TestSessionTicketManager_GetStatus 测试获取状态。 - // TestGenerateTicketKey 测试密钥生成函数。 func TestGenerateTicketKey(t *testing.T) { key1, err := generateTicketKey() @@ -295,7 +293,6 @@ func TestGenerateTicketKey(t *testing.T) { // TestSessionTicketManager_ConcurrentAccess 测试并发访问。 - // BenchmarkGenerateTicketKey 基准测试密钥生成。 func BenchmarkGenerateTicketKey(b *testing.B) { for b.Loop() { diff --git a/internal/ssl/ssl.go b/internal/ssl/ssl.go index 3d5b850..98d2959 100644 --- a/internal/ssl/ssl.go +++ b/internal/ssl/ssl.go @@ -414,5 +414,3 @@ func matchMarker(data []byte, marker []byte) bool { } return true } - - diff --git a/internal/ssl/ssl_bench_test.go b/internal/ssl/ssl_bench_test.go index 836fc98..c5e1224 100644 --- a/internal/ssl/ssl_bench_test.go +++ b/internal/ssl/ssl_bench_test.go @@ -363,19 +363,16 @@ func BenchmarkOCSPStapling_Miss(b *testing.B) { // // 测量 GetStatus 方法获取证书状态信息的开销。 - // BenchmarkSessionResumption 基准测试使用 Session Ticket 的会话恢复性能。 // // 使用 ClientSessionCache 实现会话恢复, // 测量使用缓存 session 时的握手开销。 - // BenchmarkSessionResumption_FullHandshake 基准测试完整握手(无会话恢复)。 // // 作为对照组,测量没有 session ticket 的完整 TLS 握手开销, // 与 BenchmarkSessionResumption 对比评估会话恢复的性能提升。 - // BenchmarkSessionTicketManager_ApplyToTLSConfig 基准测试应用 Session Ticket 到 TLS 配置的开销。 func BenchmarkSessionTicketManager_ApplyToTLSConfig(b *testing.B) { sessionMgr, err := NewSessionTicketManager(config.SessionTicketsConfig{ @@ -408,7 +405,6 @@ func BenchmarkSessionTicketManager_ApplyToTLSConfig(b *testing.B) { // // 测量 GetCertificate 回调在多证书场景下的查找开销。 - // BenchmarkCipherSuiteParsing 基准测试加密套件解析性能。 func BenchmarkCipherSuiteParsing(b *testing.B) { ciphers := []string{ diff --git a/internal/ssl/ssl_test.go b/internal/ssl/ssl_test.go index 79fd2a2..9a8e21c 100644 --- a/internal/ssl/ssl_test.go +++ b/internal/ssl/ssl_test.go @@ -271,12 +271,6 @@ func TestIsInsecureCipher(t *testing.T) { } } - - - - - - // generateTestCert generates a self-signed certificate for testing func generateTestCert(t *testing.T) ([]byte, []byte) { t.Helper() @@ -504,7 +498,6 @@ func TestNewTLSManager_Errors(t *testing.T) { // TestNewTLSManager_InvalidCipher 测试无效加密套件 - // TestNewTLSManager_InsecureCipher 测试不安全加密套件 func TestNewTLSManager_InsecureCipher(t *testing.T) { tmpDir := t.TempDir() @@ -533,28 +526,20 @@ func TestNewTLSManager_InsecureCipher(t *testing.T) { // TestNewMultiTLSManager 测试多证书 TLS 管理器 - // TestNewMultiTLSManager_EmptyConfigs 测试空配置 - // TestNewMultiTLSManager_NilConfig 测试 nil 配置项 - // TestGetCertificate 测试证书获取回调 - // TestAddCertificate 测试添加证书 - // TestAddCertificate_Error 测试添加证书错误 - // TestRemoveCertificate 测试移除证书 - // TestGetOCSPStatus_NoManager 测试无 OCSP 管理器时的状态 - // TestParsePEMChain 测试 PEM 证书链解析 func TestParsePEMChain(t *testing.T) { // 测试有效的 PEM 数据 @@ -657,19 +642,14 @@ func TestMatchMarker(t *testing.T) { // TestGetCertificate_NoCertificate 测试无证书时的错误情况 - // TestGetConfigForClientWithOCSP 测试 OCSP 配置回调 - // TestLoadCertificate_WithCertChain 测试带证书链的加载 - // TestLoadCertificate_InvalidChain 测试无效证书链 - // TestCreateTLSConfig_NilConfig 测试 nil 配置 - // TestNewTLSManager_WithSessionTickets 测试启用 Session Tickets func TestNewTLSManager_WithSessionTickets(t *testing.T) { tmpDir := t.TempDir() diff --git a/internal/stream/stream.go b/internal/stream/stream.go index 4e6bb9b..78659d6 100644 --- a/internal/stream/stream.go +++ b/internal/stream/stream.go @@ -994,5 +994,3 @@ func (s *udpServer) cleanupExpiredSessions() { } } } - - diff --git a/internal/stream/stream_coverage_test.go b/internal/stream/stream_coverage_test.go index cd6d14c..0f20ed3 100644 --- a/internal/stream/stream_coverage_test.go +++ b/internal/stream/stream_coverage_test.go @@ -215,24 +215,6 @@ func TestHandleConnection_DialFail(t *testing.T) { } } - - - - - - - - - - - - - - - - - - // TestAcceptLoop_Error 测试 acceptLoop 错误处理路径 func TestAcceptLoop_Error(t *testing.T) { s := NewServer() diff --git a/internal/stream/stream_test.go b/internal/stream/stream_test.go index 847b59c..387e63b 100644 --- a/internal/stream/stream_test.go +++ b/internal/stream/stream_test.go @@ -195,8 +195,6 @@ func TestIPHashBalancer(t *testing.T) { } } - - func TestUpstreamSelect(t *testing.T) { u := &Upstream{ targets: []*Target{ @@ -239,10 +237,6 @@ func TestTargetHealthy(t *testing.T) { } } - - - - func TestConcurrentConnections(t *testing.T) { s := NewServer() @@ -265,8 +259,6 @@ func TestConcurrentConnections(t *testing.T) { } } - - func TestUDPServerInvalidUpstream(t *testing.T) { s := NewServer() @@ -277,8 +269,6 @@ func TestUDPServerInvalidUpstream(t *testing.T) { } } - - func TestUDPSessionKey(t *testing.T) { addr1, _ := net.ResolveUDPAddr("udp", "127.0.0.1:1234") addr2, _ := net.ResolveUDPAddr("udp", "127.0.0.1:5678") @@ -322,10 +312,6 @@ func TestNewUDPServer(t *testing.T) { } } - - - - func TestRoundRobinBalancerWithSingleTarget(t *testing.T) { rb := newRoundRobin() targets := []*Target{ @@ -389,8 +375,6 @@ func TestAddUpstreamWithLeastConn(t *testing.T) { } } - - func TestUpstreamSelectNoHealthy(t *testing.T) { u := &Upstream{ targets: []*Target{ @@ -442,8 +426,6 @@ func TestCleanupExpiredSessions(t *testing.T) { srv.mu.RUnlock() } - - func TestUDPSessionOperations(t *testing.T) { // 创建 UDP 连接 udpAddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:0") diff --git a/internal/utils/httperror.go b/internal/utils/httperror.go index 7c2127a..21c97e4 100644 --- a/internal/utils/httperror.go +++ b/internal/utils/httperror.go @@ -23,20 +23,20 @@ type HTTPError struct { // Predefined common HTTP errors. var ( -// ErrNotFound 资源未找到错误。 - ErrNotFound = HTTPError{Message: "Not Found", StatusCode: fasthttp.StatusNotFound} + // ErrNotFound 资源未找到错误。 + ErrNotFound = HTTPError{Message: "Not Found", StatusCode: fasthttp.StatusNotFound} // ErrForbidden 禁止访问错误。 - ErrForbidden = HTTPError{Message: "Forbidden", StatusCode: fasthttp.StatusForbidden} + ErrForbidden = HTTPError{Message: "Forbidden", StatusCode: fasthttp.StatusForbidden} // ErrUnauthorized 未授权错误。 - ErrUnauthorized = HTTPError{Message: "Unauthorized", StatusCode: fasthttp.StatusUnauthorized} + ErrUnauthorized = HTTPError{Message: "Unauthorized", StatusCode: fasthttp.StatusUnauthorized} // ErrBadGateway 错误网关错误。 - ErrBadGateway = HTTPError{Message: "Bad Gateway", StatusCode: fasthttp.StatusBadGateway} + ErrBadGateway = HTTPError{Message: "Bad Gateway", StatusCode: fasthttp.StatusBadGateway} // ErrGatewayTimeout 网关超时错误。 - ErrGatewayTimeout = HTTPError{Message: "Gateway Timeout", StatusCode: fasthttp.StatusGatewayTimeout} + ErrGatewayTimeout = HTTPError{Message: "Gateway Timeout", StatusCode: fasthttp.StatusGatewayTimeout} // ErrInternalError 内部服务器错误。 - ErrInternalError = HTTPError{Message: "Internal Server Error", StatusCode: fasthttp.StatusInternalServerError} + ErrInternalError = HTTPError{Message: "Internal Server Error", StatusCode: fasthttp.StatusInternalServerError} // ErrTooManyRequests 请求过多错误。 - ErrTooManyRequests = HTTPError{Message: "Too Many Requests", StatusCode: fasthttp.StatusTooManyRequests} + ErrTooManyRequests = HTTPError{Message: "Too Many Requests", StatusCode: fasthttp.StatusTooManyRequests} // ErrServiceUnavailable 服务不可用错误。 ErrServiceUnavailable = HTTPError{Message: "Service Unavailable", StatusCode: fasthttp.StatusServiceUnavailable} ) diff --git a/internal/utils/internal.go b/internal/utils/internal.go index 4b79c1e..df27361 100644 --- a/internal/utils/internal.go +++ b/internal/utils/internal.go @@ -31,5 +31,3 @@ func GetInternalRedirectPath(ctx *fasthttp.RequestCtx) string { } return "" } - - diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 53caca2..8d76f45 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -166,8 +166,6 @@ func TestInternalRedirectKey(t *testing.T) { } } - - // TestHTTPError_CustomErrors 测试自定义 HTTPError func TestHTTPError_CustomErrors(t *testing.T) { tests := []struct { diff --git a/internal/variable/builtin.go b/internal/variable/builtin.go index e01e9cc..30b8de5 100644 --- a/internal/variable/builtin.go +++ b/internal/variable/builtin.go @@ -16,7 +16,7 @@ import ( // 内置变量常量 const ( -// VarHost 请求主机名变量。 + // VarHost 请求主机名变量。 VarHost = "host" // VarRemoteAddr 客户端地址变量。 VarRemoteAddr = "remote_addr" @@ -301,5 +301,3 @@ func SetResponseInfoInContext(ctx *fasthttp.RequestCtx, status int, bodySize int ctx.SetUserValue(VarBodyBytesSent, bodySize) ctx.SetUserValue(VarRequestTime, durationNs) } - - diff --git a/internal/variable/ssl.go b/internal/variable/ssl.go index cec2d3d..dd6141f 100644 --- a/internal/variable/ssl.go +++ b/internal/variable/ssl.go @@ -18,24 +18,24 @@ import ( // SSL 变量常量 const ( -// VarSSLClientVerify SSL 客户端证书验证结果变量。 - VarSSLClientVerify = "ssl_client_verify" + // VarSSLClientVerify SSL 客户端证书验证结果变量。 + VarSSLClientVerify = "ssl_client_verify" // VarSSLClientSerial SSL 客户端证书序列号变量。 - VarSSLClientSerial = "ssl_client_serial" + VarSSLClientSerial = "ssl_client_serial" // VarSSLClientSubject SSL 客户端证书主题变量。 - VarSSLClientSubject = "ssl_client_subject" + VarSSLClientSubject = "ssl_client_subject" // VarSSLClientIssuer SSL 客户端证书颁发者变量。 - VarSSLClientIssuer = "ssl_client_issuer" + VarSSLClientIssuer = "ssl_client_issuer" // VarSSLClientFingerprint SSL 客户端证书指纹变量。 VarSSLClientFingerprint = "ssl_client_fingerprint" // VarSSLClientNotBefore SSL 客户端证书生效时间变量。 - VarSSLClientNotBefore = "ssl_client_notbefore" + VarSSLClientNotBefore = "ssl_client_notbefore" // VarSSLClientNotAfter SSL 客户端证书过期时间变量。 - VarSSLClientNotAfter = "ssl_client_notafter" + VarSSLClientNotAfter = "ssl_client_notafter" // VarSSLClientDNS SSL 客户端证书主题 DN 变量。 - VarSSLClientDNS = "ssl_client_s_dn" + VarSSLClientDNS = "ssl_client_s_dn" // VarSSLClientEmail SSL 客户端证书邮箱变量。 - VarSSLClientEmail = "ssl_client_email" + VarSSLClientEmail = "ssl_client_email" sslProtocolNone = "NONE" ) @@ -281,5 +281,3 @@ func GetSSLClientEmail(ctx *fasthttp.RequestCtx) string { } return "" } - - diff --git a/internal/variable/ssl_test.go b/internal/variable/ssl_test.go index 6bc5d7c..60dedb6 100644 --- a/internal/variable/ssl_test.go +++ b/internal/variable/ssl_test.go @@ -296,20 +296,6 @@ func TestGetSSLClientEmail(t *testing.T) { } } - - - - - - - - - - - - - - // TestSSLVariablesInContext 测试通过 VariableContext 访问 SSL 变量 // 注意:ssl_client_verify 在非 TLS 连接下会返回 NONE(因为 GetSSLClientVerify 检查 ctx.IsTLS()) func TestSSLVariablesInContext(t *testing.T) { diff --git a/internal/variable/variable.go b/internal/variable/variable.go index 3b9d09d..ebc50d3 100644 --- a/internal/variable/variable.go +++ b/internal/variable/variable.go @@ -548,5 +548,3 @@ func (vc *Context) Expand(template string) string { return vc.Get(name) }, true) } - - diff --git a/internal/variable/variable_bench_test.go b/internal/variable/variable_bench_test.go index 56e2627..26623d6 100644 --- a/internal/variable/variable_bench_test.go +++ b/internal/variable/variable_bench_test.go @@ -173,8 +173,6 @@ func BenchmarkVariableSetAndGet(b *testing.B) { } } - - // BenchmarkVariableExpandLongTemplate 测试长模板展开性能。 // // 模拟完整访问日志格式,约 200 字符。 diff --git a/internal/variable/variable_test.go b/internal/variable/variable_test.go index 79bfd56..2481408 100644 --- a/internal/variable/variable_test.go +++ b/internal/variable/variable_test.go @@ -282,10 +282,6 @@ func TestResponseInfoVariables(t *testing.T) { } } - - - - // BenchmarkExpandSimple 基准测试:简单变量展开 func BenchmarkExpandSimple(b *testing.B) { ctx := &fasthttp.RequestCtx{} @@ -375,8 +371,6 @@ func BenchmarkPoolGetPut(b *testing.B) { } } - - // TestPoolReuse 测试池复用 func TestPoolReuse(t *testing.T) { ctx := mockRequestCtx(t) @@ -399,8 +393,6 @@ func TestPoolReuse(t *testing.T) { ReleaseContext(vc2) } - - // TestReleaseNilContext 测试释放 nil context func TestReleaseNilContext(_ *testing.T) { // 不应该 panic @@ -422,12 +414,6 @@ func TestGetBuiltin(t *testing.T) { } } - - - - - - // TestEmptyTemplate 测试空模板 func TestEmptyTemplate(t *testing.T) { ctx := mockRequestCtx(t) @@ -501,8 +487,6 @@ func TestPoolPutNil(_ *testing.T) { ReleaseContext(nil) } - - // TestSetResponseInfo 测试 SetResponseInfo func TestSetResponseInfo(t *testing.T) { ctx := mockRequestCtx(t) @@ -535,16 +519,6 @@ func TestSetServerName(t *testing.T) { } } - - - - - - - - - - // TestUpstreamVariables 测试上游变量 func TestUpstreamVariables(t *testing.T) { ctx := mockRequestCtx(t) @@ -749,12 +723,6 @@ func BenchmarkUpstreamVariables(b *testing.B) { } } - - - - - - // TestEphemeralGet 测试 EphemeralGet 方法 func TestEphemeralGet(t *testing.T) { ctx := mockRequestCtx(t)