mirror of
https://github.com/Xevion/banner.git
synced 2025-12-09 16:06:32 -06:00
NoCache, onRequest/onResponse, pluralizer helpers
This commit is contained in:
24
helpers.go
24
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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user