diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-08-25 09:48:07 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-08-25 09:48:07 +0200 |
commit | f335be06085e8f8105246fd84a5e568c4e193c15 (patch) | |
tree | c4e2075f8f0126b2a1e089066443ec9f1b440d40 /client/go/util/http.go | |
parent | c43e37dcfb49d50a2b4109e4f8ac9a1d3ae0609e (diff) |
go fmt
Diffstat (limited to 'client/go/util/http.go')
-rw-r--r-- | client/go/util/http.go | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/client/go/util/http.go b/client/go/util/http.go index 24e2416117c..6a4bab6c108 100644 --- a/client/go/util/http.go +++ b/client/go/util/http.go @@ -5,51 +5,51 @@ package util import ( - "net/http" - "net/url" - "strings" - "time" + "net/http" + "net/url" + "strings" + "time" ) // Set this to a mock HttpClient instead to unit test HTTP requests var ActiveHttpClient = CreateClient(time.Second * 10) type HttpClient interface { - Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) + Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) } type defaultHttpClient struct { - client *http.Client + client *http.Client } func (c *defaultHttpClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) { - if c.client.Timeout != timeout { // Create a new client with the right timeout - c.client = &http.Client{Timeout: timeout,} - } - return c.client.Do(request) + if c.client.Timeout != timeout { // Create a new client with the right timeout + c.client = &http.Client{Timeout: timeout} + } + return c.client.Do(request) } func CreateClient(timeout time.Duration) HttpClient { - return &defaultHttpClient{ - client: &http.Client{Timeout: timeout,}, - } + return &defaultHttpClient{ + client: &http.Client{Timeout: timeout}, + } } // Convenience function for doing a HTTP GET func HttpGet(host string, path string, description string) *http.Response { - url, urlError := url.Parse(host + path) - if urlError != nil { - Error("Invalid target url '" + host + path + "'") - return nil - } - return HttpDo(&http.Request{URL: url,}, time.Second * 10, description) + url, urlError := url.Parse(host + path) + if urlError != nil { + Error("Invalid target url '" + host + path + "'") + return nil + } + return HttpDo(&http.Request{URL: url}, time.Second*10, description) } func HttpDo(request *http.Request, timeout time.Duration, description string) *http.Response { - response, error := ActiveHttpClient.Do(request, timeout) - if error != nil { - Error("Could not connect to", strings.ToLower(description), "at", request.URL.Host) - Detail(error.Error()) - } - return response + response, error := ActiveHttpClient.Do(request, timeout) + if error != nil { + Error("Could not connect to", strings.ToLower(description), "at", request.URL.Host) + Detail(error.Error()) + } + return response } |