From 6d7304c395299d941b3db483220da1cbca8308ca Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 8 Dec 2023 16:01:34 -0600 Subject: [PATCH] Contain authentication & request building helpers --- helpers.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/helpers.go b/helpers.go index 14cb719..5572407 100644 --- a/helpers.go +++ b/helpers.go @@ -1,11 +1,13 @@ package banner import ( + "io" + "math/rand" "net/http" "strings" ) -func buildURL(path string, params map[string]string) string { +func BuildRequestWithBody(method string, path string, params map[string]string, body io.Reader) *http.Request { // Builds a URL for the given path and parameters url := baseURL + path @@ -22,7 +24,13 @@ func buildURL(path string, params map[string]string) string { } } - return url + request, _ := http.NewRequest(method, url, body) + AddUserAgent(request) + return request +} + +func BuildRequest(method string, path string, params map[string]string) *http.Request { + return BuildRequestWithBody(method, path, params, nil) } func AddUserAgent(req *http.Request) { @@ -38,3 +46,13 @@ func ContainsContentType(header string, search string) bool { } return false } + +const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + +func RandomString(n int) string { + b := make([]byte, n) + for i := range b { + b[i] = letterBytes[rand.Intn(len(letterBytes))] + } + return string(b) +}