summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-15 11:01:37 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-15 11:01:37 -0600
commit2d25eb7f7bb2d091c0c1d243f5a9bd1c7ff98ea1 (patch)
treea4b46546ac72ce5e353211c7525ecd33deb50ce2
parent1460e1bac2f107e715de55656e4e9c3e7a59cec3 (diff)
fix HTTP cache
-rw-r--r--cmd/generate/httpcache.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/cmd/generate/httpcache.go b/cmd/generate/httpcache.go
index 7debd0a..87d2fb5 100644
--- a/cmd/generate/httpcache.go
+++ b/cmd/generate/httpcache.go
@@ -10,17 +10,25 @@ import (
var httpCache = map[string]string{}
func httpGet(u string) (string, error) {
+ if cache, ok := httpCache[u]; ok {
+ return cache, nil
+ }
+ fmt.Printf("GET %q...", u)
resp, err := http.Get(u)
if err != nil {
+ fmt.Printf(" err\n")
return "", err
}
if resp.StatusCode != http.StatusOK {
+ fmt.Printf(" err\n")
return "", fmt.Errorf("unexpected HTTP status: %v", resp.Status)
}
bs, err := io.ReadAll(resp.Body)
if err != nil {
+ fmt.Printf(" err\n")
return "", err
}
+ fmt.Printf(" ok\n")
httpCache[u] = string(bs)
return httpCache[u], nil
}