mirror of
https://github.com/Xevion/banner.git
synced 2025-12-13 12:11:04 -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 (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func BuildRequestWithBody(method string, path string, params map[string]string, body io.Reader) *http.Request {
|
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)
|
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