From b9358a0e8ddb3f15aaf8abe6c59045c1c6c69d19 Mon Sep 17 00:00:00 2001 From: Justin Harms Date: Tue, 2 Sep 2025 05:03:15 -0500 Subject: [PATCH] Refactor steamcache.go to simplify code and improve readability - Removed the min function and the verifyResponseHash function to streamline the codebase. - Updated extractHashFromSteamPath to use strings.TrimPrefix for cleaner path handling. - Retained comments regarding removed Prometheus metrics for future reference. --- steamcache/steamcache.go | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/steamcache/steamcache.go b/steamcache/steamcache.go index db11602..5f414c4 100644 --- a/steamcache/steamcache.go +++ b/steamcache/steamcache.go @@ -28,24 +28,10 @@ import ( "github.com/docker/go-units" ) -// min returns the minimum of two integers -func min(a, b int) int { - if a < b { - return a - } - return b -} - -// Removed Prometheus metrics - keeping this comment for reference: -// requestsTotal, cacheStatusTotal, responseTime, hashVerificationTotal - // extractHashFromSteamPath extracts a hash from Steam depot URLs // Handles patterns like: /depot/123/chunk/abcdef... or /depot/123/manifest/456/789/hash func extractHashFromSteamPath(path string) (string, bool) { - // Remove leading slash - if strings.HasPrefix(path, "/") { - path = path[1:] - } + path = strings.TrimPrefix(path, "/") parts := strings.Split(path, "/") if len(parts) < 3 { @@ -136,12 +122,6 @@ func verifyFileHash(data []byte, expectedHash string) bool { return strings.EqualFold(actualHash, expectedHash) } -// verifyResponseHash verifies that the full HTTP response matches the expected hash -func verifyResponseHash(resp *http.Response, bodyData []byte, expectedHash string) bool { - actualHash := calculateResponseHash(resp, bodyData) - return strings.EqualFold(actualHash, expectedHash) -} - var hopByHopHeaders = map[string]struct{}{ "Connection": {}, "Keep-Alive": {},