From 8f8c4c31024af1fbcce3cdc38f2ff34d4538ad94 Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 9 Dec 2023 16:54:24 -0600 Subject: [PATCH] NoCache, onRequest/onResponse, pluralizer helpers --- helpers.go | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/helpers.go b/helpers.go index 5572407..d30cd79 100644 --- a/helpers.go +++ b/helpers.go @@ -1,10 +1,13 @@ -package banner +package main import ( "io" + "log" "math/rand" "net/http" + "strconv" "strings" + "time" ) func BuildRequestWithBody(method string, path string, params map[string]string, body io.Reader) *http.Request { @@ -56,3 +59,22 @@ func RandomString(n int) string { } return string(b) } + +func NoCache() string { + return strconv.Itoa(int(time.Now().UnixMilli())) +} + +func onRequest(req *http.Request) { + log.Printf("GET %s", req.URL.String()) +} + +func onResponse(res *http.Response) { + log.Printf("%s %d %s", res.Status, res.ContentLength, res.Header["Content-Type"]) +} + +func Plural(n int) string { + if n == 1 { + return "" + } + return "s" +}