From 2c0c3771a9e0991b3f8ca13c090a6dc1131e6625 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 29 Jun 2018 16:14:54 +0200 Subject: [PATCH] Make sure to close the response body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And fix a few linter warnings while we're at it… --- config/module/storage.go | 1 + registry/client.go | 1 + svchost/disco/disco.go | 5 ++++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/module/storage.go b/config/module/storage.go index c1588d684..fa5e1c621 100644 --- a/config/module/storage.go +++ b/config/module/storage.go @@ -78,6 +78,7 @@ type Storage struct { registry *registry.Client } +// NewStorage returns a new initialized Storage object. func NewStorage(dir string, services *disco.Disco, creds auth.CredentialsSource) *Storage { regClient := registry.NewClient(services, creds, nil) diff --git a/registry/client.go b/registry/client.go index aefed84af..fba59ec87 100644 --- a/registry/client.go +++ b/registry/client.go @@ -43,6 +43,7 @@ type Client struct { creds auth.CredentialsSource } +// NewClient returns a new initialized registry client. func NewClient(services *disco.Disco, creds auth.CredentialsSource, client *http.Client) *Client { if services == nil { services = disco.NewDisco() diff --git a/svchost/disco/disco.go b/svchost/disco/disco.go index 144384e04..76a1b3b0d 100644 --- a/svchost/disco/disco.go +++ b/svchost/disco/disco.go @@ -42,6 +42,7 @@ type Disco struct { Transport http.RoundTripper } +// NewDisco returns a new initialized Disco object. func NewDisco() *Disco { return &Disco{} } @@ -117,7 +118,7 @@ func (d *Disco) DiscoverServiceURL(host svchost.Hostname, serviceID string) *url func (d *Disco) discover(host svchost.Hostname) Host { discoURL := &url.URL{ Scheme: "https", - Host: string(host), + Host: host.String(), Path: discoPath, } @@ -166,6 +167,8 @@ func (d *Disco) discover(host svchost.Hostname) Host { log.Printf("[WARN] Failed to request discovery document: %s", err) return ret // empty } + defer resp.Body.Close() + if resp.StatusCode != 200 { log.Printf("[WARN] Failed to request discovery document: %s", resp.Status) return ret // empty