diff --git a/src/handlers/docker.go b/src/handlers/docker.go index eb89a35..39dc554 100644 --- a/src/handlers/docker.go +++ b/src/handlers/docker.go @@ -274,7 +274,9 @@ func handleBlobRequest(c *gin.Context, imageRef, digest string) { c.Header("Docker-Content-Digest", digest) c.Status(http.StatusOK) - io.Copy(c.Writer, reader) + if _, err := io.Copy(c.Writer, reader); err != nil { + fmt.Printf("复制layer内容失败: %v\n", err) + } } // handleTagsRequest 处理tags列表请求 @@ -416,7 +418,9 @@ func proxyDockerAuthOriginal(c *gin.Context) { } c.Status(resp.StatusCode) - io.Copy(c.Writer, resp.Body) + if _, err := io.Copy(c.Writer, resp.Body); err != nil { + fmt.Printf("复制认证响应失败: %v\n", err) + } } // rewriteAuthHeader 重写认证头 @@ -569,7 +573,9 @@ func handleUpstreamBlobRequest(c *gin.Context, imageRef, digest string, mapping c.Header("Docker-Content-Digest", digest) c.Status(http.StatusOK) - io.Copy(c.Writer, reader) + if _, err := io.Copy(c.Writer, reader); err != nil { + fmt.Printf("复制layer内容失败: %v\n", err) + } } // handleUpstreamTagsRequest 处理上游Registry的tags请求 diff --git a/src/handlers/github.go b/src/handlers/github.go index d845851..8697118 100644 --- a/src/handlers/github.go +++ b/src/handlers/github.go @@ -227,6 +227,8 @@ func proxyGitHubWithRedirect(c *gin.Context, u string, redirectCount int) { c.Status(resp.StatusCode) // 直接流式转发 - io.Copy(c.Writer, resp.Body) + if _, err := io.Copy(c.Writer, resp.Body); err != nil { + fmt.Printf("转发响应体失败: %v\n", err) + } } } diff --git a/src/handlers/search.go b/src/handlers/search.go index 7c2ec2a..7deaebc 100644 --- a/src/handlers/search.go +++ b/src/handlers/search.go @@ -7,7 +7,6 @@ import ( "io" "net/http" "net/url" - "sort" "strings" "sync" "time" @@ -160,51 +159,6 @@ func init() { }() } -func filterSearchResults(results []Repository, query string) []Repository { - searchTerm := strings.ToLower(strings.TrimPrefix(query, "library/")) - filtered := make([]Repository, 0) - - for _, repo := range results { - repoName := strings.ToLower(repo.Name) - repoDesc := strings.ToLower(repo.Description) - - score := 0 - - if repoName == searchTerm { - score += 100 - } - - if strings.HasPrefix(repoName, searchTerm) { - score += 50 - } - - if strings.Contains(repoName, searchTerm) { - score += 30 - } - - if strings.Contains(repoDesc, searchTerm) { - score += 10 - } - - if repo.IsOfficial { - score += 20 - } - - if score > 0 { - filtered = append(filtered, repo) - } - } - - sort.Slice(filtered, func(i, j int) bool { - if filtered[i].IsOfficial != filtered[j].IsOfficial { - return filtered[i].IsOfficial - } - return filtered[i].PullCount > filtered[j].PullCount - }) - - return filtered -} - // normalizeRepository 统一规范化仓库信息 func normalizeRepository(repo *Repository) { if repo.IsOfficial { @@ -487,10 +441,14 @@ func parsePaginationParams(c *gin.Context, defaultPageSize int) (page, pageSize pageSize = defaultPageSize if p := c.Query("page"); p != "" { - fmt.Sscanf(p, "%d", &page) + if _, err := fmt.Sscanf(p, "%d", &page); err != nil { + fmt.Printf("解析page参数失败: %v\n", err) + } } if ps := c.Query("page_size"); ps != "" { - fmt.Sscanf(ps, "%d", &pageSize) + if _, err := fmt.Sscanf(ps, "%d", &pageSize); err != nil { + fmt.Printf("解析page_size参数失败: %v\n", err) + } } return page, pageSize diff --git a/src/utils/access_control.go b/src/utils/access_control.go index 9912276..d676177 100644 --- a/src/utils/access_control.go +++ b/src/utils/access_control.go @@ -2,7 +2,6 @@ package utils import ( "strings" - "sync" "hubproxy/config" ) @@ -17,7 +16,6 @@ const ( // AccessController 统一访问控制器 type AccessController struct { - mu sync.RWMutex } // DockerImageInfo Docker镜像信息 diff --git a/src/utils/ratelimiter.go b/src/utils/ratelimiter.go index 0658ff6..3512cc9 100644 --- a/src/utils/ratelimiter.go +++ b/src/utils/ratelimiter.go @@ -176,8 +176,9 @@ func (i *IPRateLimiter) GetLimiter(ip string) (*rate.Limiter, bool) { now := time.Now() + var entry *rateLimiterEntry i.mu.RLock() - entry, exists := i.ips[normalizedIP] + _, exists := i.ips[normalizedIP] i.mu.RUnlock() if exists {