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.
This commit is contained in:
2025-09-02 05:03:15 -05:00
parent c197841960
commit b9358a0e8d

View File

@@ -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": {},