Skip to content

Commit aa7d697

Browse files
go fix updates
1 parent 8d64ade commit aa7d697

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

internal/cacheable_response.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/gob"
66
"io"
77
"log/slog"
8+
"maps"
89
"net/http"
910
"regexp"
1011
"strconv"
@@ -149,9 +150,7 @@ func (c *CacheableResponse) wasNotModified(r *http.Request) bool {
149150
}
150151

151152
func (c *CacheableResponse) copyHeaders(w http.ResponseWriter, wasHit bool, statusCode int) {
152-
for k, v := range c.HttpHeader {
153-
w.Header()[k] = v
154-
}
153+
maps.Copy(w.Header(), c.HttpHeader)
155154

156155
if wasHit {
157156
w.Header().Set("X-Cache", "hit")

internal/compression_guard_handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func hasUserSpecificResponseHeaders(h http.Header) bool {
6060
}
6161

6262
cacheControl := strings.ToLower(h.Get("Cache-Control"))
63-
for _, directive := range strings.Split(cacheControl, ",") {
63+
for directive := range strings.SplitSeq(cacheControl, ",") {
6464
dir := strings.TrimSpace(directive)
6565
// Strip any value (e.g. private="Set-Cookie") before comparison.
6666
dirName := strings.SplitN(dir, "=", 2)[0]
@@ -70,7 +70,7 @@ func hasUserSpecificResponseHeaders(h http.Header) bool {
7070
}
7171

7272
vary := h.Get("Vary")
73-
for _, token := range strings.Split(vary, ",") {
73+
for token := range strings.SplitSeq(vary, ",") {
7474
if strings.EqualFold(strings.TrimSpace(token), "cookie") {
7575
return true
7676
}

internal/memory_cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (c *MemoryCache) evictOldestItem() {
101101
//
102102
// If we find an expired item while looking, that's a better choice to evict,
103103
// so we can choose it immediately.
104-
for i := 0; i < 5; i++ {
104+
for range 5 {
105105
index := rand.Intn(len(c.keys))
106106
key := c.keys[index]
107107
v := c.items[key]

internal/memory_cache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestMemoryCache_items_are_evicted_to_make_space(t *testing.T) {
7676
maxCacheSize := 10 * KB
7777
c := NewMemoryCache(maxCacheSize, 1*KB)
7878

79-
for i := CacheKey(0); i < 20; i++ {
79+
for i := range CacheKey(20) {
8080
payload := bytes.Repeat([]byte{byte(i)}, 1*KB)
8181
c.Set(i, payload, time.Now().Add(1*time.Hour))
8282

0 commit comments

Comments
 (0)