summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-20 18:25:11 -0400
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-05-21 00:04:19 -0400
commitf9914b279ac955ff250a7f5cefdaad5c890b3300 (patch)
treed855342ace80e55e94d52279deed4afc5fe3ffa7
parentef1cee941240b3f7168f4a74685109053bdfb6f4 (diff)
Set up to share the HTTP cache
-rw-r--r--cmd/gen-imworkingon/main.go7
-rw-r--r--lib/httpcache/httpcache.go7
2 files changed, 11 insertions, 3 deletions
diff --git a/cmd/gen-imworkingon/main.go b/cmd/gen-imworkingon/main.go
index 4f020b8..c0c9723 100644
--- a/cmd/gen-imworkingon/main.go
+++ b/cmd/gen-imworkingon/main.go
@@ -4,6 +4,7 @@ import (
"bytes"
_ "embed"
"fmt"
+ "html/template"
"os"
"reflect"
"slices"
@@ -11,9 +12,9 @@ import (
"strings"
"time"
- "html/template"
-
"github.com/yuin/goldmark"
+
+ "git.lukeshu.com/www/lib/httpcache"
)
func MarkdownToHTML(md string) (template.HTML, error) {
@@ -38,6 +39,8 @@ var timeTagTmpl = template.Must(template.New("time.tag.tmpl").
Parse(`<time datetime="{{ .Machine }}" title="{{ .HumanVerbose }}">{{ .HumanPretty }}</time>`))
func mainWithError() error {
+ httpcache.UserAgent = "https://git.lukeshu.com/www/tree/cmd/gen-imworkingon"
+
standups, err := ReadStandups("https://social.coop", "lukeshu")
if err != nil {
return err
diff --git a/lib/httpcache/httpcache.go b/lib/httpcache/httpcache.go
index 0fb8268..aded85c 100644
--- a/lib/httpcache/httpcache.go
+++ b/lib/httpcache/httpcache.go
@@ -11,6 +11,8 @@ import (
"sort"
)
+var UserAgent string
+
type httpCacheEntry struct {
Body string
Err error
@@ -39,6 +41,9 @@ func (e *httpStatusError) Error() string {
}
func Get(u string, hdr map[string]string) (string, error) {
+ if UserAgent == "" {
+ panic("main() must set the user agent string")
+ }
cacheKey := url.QueryEscape(u)
hdrKeys := make([]string, 0, len(hdr))
for k := range hdr {
@@ -72,7 +77,7 @@ func Get(u string, hdr map[string]string) (string, error) {
httpCache[cacheKey] = httpCacheEntry{Err: err}
return "", err
}
- req.Header.Set("User-Agent", "https://git.lukeshu.com/www/tree/cmd/gen-imworkingon")
+ req.Header.Set("User-Agent", UserAgent)
for k, v := range hdr {
req.Header.Add(k, v)
}