NoCache, onRequest/onResponse, pluralizer helpers

This commit is contained in:
2023-12-09 16:54:24 -06:00
parent 732a7445dc
commit 8f8c4c3102

View File

@@ -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"
}