From 2d25eb7f7bb2d091c0c1d243f5a9bd1c7ff98ea1 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Mon, 15 Apr 2024 11:01:37 -0600 Subject: fix HTTP cache --- cmd/generate/httpcache.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cmd/generate') 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 } -- cgit v1.2.3-2-g168b