Remove pre go1.8 code and cleanup (#4933)

We don't need certain go1.7.x custom code anymore, since
we have migrated to go1.8
This commit is contained in:
Harshavardhana 2017-09-22 14:03:31 -07:00 committed by Dee Koder
parent 6d7df1d1cb
commit 330f79b40e
2 changed files with 14 additions and 44 deletions

View File

@ -111,7 +111,7 @@ func lookupEndpoint(urlStr string) error {
client := &http.Client{
Timeout: 1 * time.Second,
Transport: &http.Transport{
// need to close connection after usage.
// Need to close connection after usage.
DisableKeepAlives: true,
},
}
@ -122,51 +122,21 @@ func lookupEndpoint(urlStr string) error {
// Set proper server user-agent.
req.Header.Set("User-Agent", globalServerUserAgent)
// Retry if the request needs to be re-directed.
// This code is necessary since Go 1.7.x do not
// support retrying for http 307 for POST operation.
// https://github.com/golang/go/issues/7912
//
// FIXME: Remove this when we move to Go 1.8.
for {
resp, derr := client.Do(req)
if derr != nil {
if isNetErrorIgnored(derr) {
errorIf(derr, "Unable to lookup webhook endpoint %s", urlStr)
resp, err := client.Do(req)
if err != nil {
if isNetErrorIgnored(err) {
errorIf(err, "Unable to lookup webhook endpoint %s", urlStr)
return nil
}
return derr
}
if resp == nil {
return fmt.Errorf("No response from server to download URL %s", urlStr)
}
resp.Body.Close()
// Redo the request with the new redirect url if http 307
// is returned, quit the loop otherwise
if resp.StatusCode == http.StatusTemporaryRedirect {
newURL, uerr := url.Parse(resp.Header.Get("Location"))
if uerr != nil {
return uerr
}
req.URL = newURL
continue
}
// For any known successful http status, return quickly.
for _, httpStatus := range successStatus {
if httpStatus == resp.StatusCode {
return nil
}
}
err = fmt.Errorf("Unexpected response from webhook server %s: (%s)", urlStr, resp.Status)
break
}
// Succes.
return err
}
defer resp.Body.Close()
// HTTP status OK/NoContent.
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusNoContent {
return fmt.Errorf("Unable to lookup webhook endpoint %s response(%s)", urlStr, resp.Status)
}
return nil
}
// Initializes new webhook logrus notifier.
func newWebhookNotify(accountID string) (*logrus.Logger, error) {

View File

@ -106,7 +106,7 @@ func TestLookupEndpoint(t *testing.T) {
},
{
endpoint: server.URL,
err: fmt.Errorf("Unexpected response from webhook server %s: (400 Bad Request)", server.URL),
err: fmt.Errorf("Unable to lookup webhook endpoint %s response(400 Bad Request)", server.URL),
},
}
for _, test := range testCases {