fix(lint): 修复 handler 和 http2 模块 lint 错误

- 添加 nolint:errcheck 注释到 defer Close 调用
- 修复 websocket.go 中重复的 nolint 注释格式
- 添加 staticcheck SA1019 nolint 注释到 deprecated WriteScheduler
- 移除 sendfile_linux.go 中未使用的 platformLinux 常量
- 添加文件末尾换行符

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
xfy 2026-04-13 09:51:30 +08:00
parent 326340fe4c
commit bb77fa6a98
6 changed files with 13 additions and 15 deletions

View File

@ -125,4 +125,4 @@ func platformSendfile(conn net.Conn, file *os.File, offset, length int64) error
// macOS sendfile 签名复杂,简化使用 fallback
// Windows TransmitFile 需要特殊 API
return syscall.ENOTSUP
}
}

View File

@ -22,9 +22,6 @@ const (
MinSendfileSize = 8 * 1024
)
// platformLinux Linux 平台标识符。
const platformLinux = "linux"
// SendFile 零拷贝文件传输。
//
// 大文件使用系统调用直接从文件传输到 socket避免用户空间拷贝
@ -120,16 +117,16 @@ func getSocketFd(conn net.Conn) (uintptr, error) {
if err != nil {
return 0, err
}
defer func() { _ = file.Close() }()
defer func() { _ = file.Close() }() //nolint:errcheck
return file.Fd(), nil
case *net.UnixConn:
file, err := c.File()
if err != nil {
return 0, err
}
defer func() { _ = file.Close() }()
defer func() { _ = file.Close() }() //nolint:errcheck
return file.Fd(), nil
default:
return 0, syscall.ENOTSUP
}
}
}

View File

@ -245,4 +245,4 @@ func TestCopyFile_Error(t *testing.T) {
if err == nil {
t.Error("Expected error for offset beyond file size")
}
}
}

View File

@ -277,4 +277,4 @@ func TestLinuxSendfile_NilConn(t *testing.T) {
if err == nil {
t.Error("Expected error for nil connection")
}
}
}

View File

@ -101,8 +101,9 @@ func NewServer(cfg *config.HTTP2Config, handler fasthttp.RequestHandler, tlsConf
MaxConcurrentStreams: uint32(maxConcurrentStreams),
IdleTimeout: idleTimeout,
MaxReadFrameSize: uint32(maxHeaderListSize),
NewWriteScheduler: func() http2.WriteScheduler { return http2.NewPriorityWriteScheduler(nil) },
CountError: func(_ string) {},
//nolint:staticcheck // SA1019: NewWriteScheduler deprecated
NewWriteScheduler: func() http2.WriteScheduler { return http2.NewPriorityWriteScheduler(nil) },
CountError: func(_ string) {},
}
return &Server{

View File

@ -227,11 +227,11 @@ func dialTarget(targetURL string, timeout time.Duration) (net.Conn, error) {
ServerName: strings.Split(addr, ":")[0],
})
if err := tlsConn.SetDeadline(time.Now().Add(timeout)); err != nil {
_ = conn.Close() //nolint:errcheck //nolint:errcheck
_ = conn.Close() //nolint:errcheck // 错误处理中关闭连接
return nil, fmt.Errorf("failed to set TLS deadline: %w", err)
}
if err := tlsConn.Handshake(); err != nil {
_ = conn.Close() //nolint:errcheck //nolint:errcheck
_ = conn.Close() //nolint:errcheck // 错误处理中关闭连接
return nil, fmt.Errorf("TLS handshake failed: %w", err)
}
return tlsConn, nil
@ -396,14 +396,14 @@ func WebSocket(ctx *fasthttp.RequestCtx, target *loadbalance.Target, timeout tim
// 步骤5: 检查响应状态码(期望 101 Switching Protocols
if resp.StatusCode != http.StatusSwitchingProtocols {
// 关闭响应 body升级失败时
_ = resp.Body.Close() //nolint:errcheck //nolint:errcheck
_ = resp.Body.Close() //nolint:errcheck // 错误处理中关闭响应体
return fmt.Errorf("backend rejected WebSocket upgrade: %s", resp.Status)
}
// 步骤6: 将升级响应发送回客户端
if err := writeUpgradeResponse(clientConn, resp); err != nil {
// 关闭响应 body写入失败时
_ = resp.Body.Close() //nolint:errcheck //nolint:errcheck
_ = resp.Body.Close() //nolint:errcheck // 错误处理中关闭响应体
return fmt.Errorf("failed to send upgrade response to client: %w", err)
}