Continue improving comments & use of structured logs

This commit is contained in:
2023-12-24 20:01:56 -06:00
parent 81e60ed4b7
commit 09f973c46a
4 changed files with 22 additions and 23 deletions

View File

@@ -42,9 +42,9 @@ func AddUserAgent(req *http.Request) {
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36")
}
func ContainsContentType(header string, search string) bool {
func ContainsContentType(response *http.Response, search string) bool {
// Split on commas, check if any of the types match
for _, content_type := range strings.Split(header, ";") {
for _, content_type := range strings.Split(response.Header.Get("Content-Type"), ";") {
if content_type == search {
return true
}
@@ -67,8 +67,9 @@ func Nonce() string {
return strconv.Itoa(int(time.Now().UnixMilli()))
}
// doRequest performs & logs the request, logging and returning the response
func doRequest(req *http.Request) (*http.Response, error) {
log.Debug().Str("method", req.Method).Msg("Request")
log.Debug().Str("method", strings.TrimRight(req.Method, " ")).Str("url", req.URL.String()).Str("query", req.URL.RawQuery).Str("content-type", req.Header.Get("Content-Type")).Msg("Request")
res, err := client.Do(req)
if err != nil {
log.Err(err).Str("method", req.Method).Msg("Request Failed")