From 1e38fe9e90669b2803d95ae806660e5185179dfd Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 24 Apr 2026 10:41:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=98=BE=E5=BC=8F=E5=BF=BD=E7=95=A5?= =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E5=A4=84=E7=90=86=E7=9A=84=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=BF=94=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对 os.Remove、conn.Close 等清理操作的返回值使用 _ 忽略, 避免 errcheck 静态检查告警。 Co-Authored-By: Claude Opus 4.7 --- internal/cache/disk_cache.go | 12 ++++++------ internal/lua/api_socket_tcp.go | 4 ++-- internal/middleware/security/geoip.go | 2 +- internal/server/server.go | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/cache/disk_cache.go b/internal/cache/disk_cache.go index c895a6f..14e2636 100644 --- a/internal/cache/disk_cache.go +++ b/internal/cache/disk_cache.go @@ -370,7 +370,7 @@ func (dc *DiskCache) Set(hashKey uint64, origKey string, data []byte, headers ma return } if err := os.Rename(tmpDataPath, dataPath); err != nil { - os.Remove(tmpDataPath) + _ = os.Remove(tmpDataPath) return } @@ -384,7 +384,7 @@ func (dc *DiskCache) Set(hashKey uint64, origKey string, data []byte, headers ma return } if err := os.Rename(tmpMetaPath, metaPath); err != nil { - os.Remove(tmpMetaPath) + _ = os.Remove(tmpMetaPath) return } @@ -424,8 +424,8 @@ func (dc *DiskCache) Delete(hashKey uint64) error { // 删除文件 dataPath := dc.filePathFromHash(hashKey, "data") metaPath := dc.filePathFromHash(hashKey, "meta") - os.Remove(dataPath) - os.Remove(metaPath) + _ = os.Remove(dataPath) + _ = os.Remove(metaPath) return nil } @@ -505,7 +505,7 @@ func (dc *DiskCache) evict() { // 删除文件 dataPath := dc.filePathFromHash(oldestKey, "data") metaPath := dc.filePathFromHash(oldestKey, "meta") - os.Remove(dataPath) - os.Remove(metaPath) + _ = os.Remove(dataPath) + _ = os.Remove(metaPath) } } diff --git a/internal/lua/api_socket_tcp.go b/internal/lua/api_socket_tcp.go index b1b1400..d849bfa 100644 --- a/internal/lua/api_socket_tcp.go +++ b/internal/lua/api_socket_tcp.go @@ -429,7 +429,7 @@ func (s *TCPSocket) Close() error { // 关闭连接 if s.conn != nil { - s.conn.Close() + _ = s.conn.Close() s.conn = nil } @@ -802,7 +802,7 @@ func tcpSocketSetTimeouts(L *glua.LState) int { // tcpSocketGC __gc 元方法 func tcpSocketGC(L *glua.LState) int { socket := checkTCPSocket(L, 1) - socket.Close() + _ = socket.Close() return 0 } diff --git a/internal/middleware/security/geoip.go b/internal/middleware/security/geoip.go index d7a09e6..d27bd9d 100644 --- a/internal/middleware/security/geoip.go +++ b/internal/middleware/security/geoip.go @@ -82,7 +82,7 @@ func NewGeoIPLookup(dbPath string, cacheSize int, ttl time.Duration, privateIPBe cache, err := lru.New[string, *cachedCountry](cacheSize) if err != nil { - db.Close() + _ = db.Close() return nil, fmt.Errorf("create lru cache: %w", err) } diff --git a/internal/server/server.go b/internal/server/server.go index ef1b5ab..da96fb8 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -534,7 +534,7 @@ func (s *Server) createListener(cfg *config.ServerConfig) (net.Listener, error) // 2. 清理旧 socket 文件 if _, err := os.Stat(socketPath); err == nil { - os.Remove(socketPath) + _ = os.Remove(socketPath) } // 3. 创建 Unix socket listener