diff options
Diffstat (limited to 'gopkgs/utils/utils.go')
-rw-r--r-- | gopkgs/utils/utils.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/gopkgs/utils/utils.go b/gopkgs/utils/utils.go index 24a01cea9d1d..404fd8bf0a12 100644 --- a/gopkgs/utils/utils.go +++ b/gopkgs/utils/utils.go @@ -2,8 +2,9 @@ package utils import ( - "log" + "fmt" "io/ioutil" + "log" "net/http" "net/http/httputil" ) @@ -15,6 +16,18 @@ func FailOn(err error) { } } +// Prints the verbose form of an HTTP request. +func DebugRequest(req *http.Request) { + bytes, _ := httputil.DumpRequest(req, true) + fmt.Println(string(bytes)) +} + +// Prints out the verbose form of an HTTP response. +func DebugResponse(res *http.Response) { + bytes, _ := httputil.DumpResponse(res, true) + fmt.Println(string(bytes)) +} + // Make a simple GET request to `url`. Fail if anything returns an error. I'd // like to accumulate a library of these, so that I can write scrappy Go // quickly. For now, this function just returns the body of the response back as @@ -36,10 +49,8 @@ func SimpleGet(url string, headers map[string]string, debug bool) string { defer res.Body.Close() if debug { - bytes, _ := httputil.DumpRequest(req, true) - log.Println(string(bytes)) - bytes, _ = httputil.DumpResponse(res, true) - log.Println(string(bytes)) + DebugRequest(req) + DebugResponse(res) } if res.StatusCode == http.StatusOK { |