diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-04-15 11:01:37 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-04-15 11:01:37 -0600 |
commit | 2d25eb7f7bb2d091c0c1d243f5a9bd1c7ff98ea1 (patch) | |
tree | a4b46546ac72ce5e353211c7525ecd33deb50ce2 /cmd | |
parent | 1460e1bac2f107e715de55656e4e9c3e7a59cec3 (diff) |
fix HTTP cache
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/generate/httpcache.go | 8 |
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 } |