From 3f9c7a5c009c23798d2ad20edfcc3ea6340cbb51 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 8 Jun 2015 22:36:48 +0100 Subject: [PATCH] remove pointless indirection --- proxy/client.go | 20 ++++---------------- proxy/proxy.go | 2 +- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/proxy/client.go b/proxy/client.go index 87e1a968..080872f4 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -14,20 +14,8 @@ import ( . "github.com/weaveworks/weave/common" ) -type client struct { - interceptor - Dial func() (net.Conn, error) -} - -func newClient(dial func() (net.Conn, error), i interceptor) *client { - return &client{ - interceptor: i, - Dial: dial, - } -} - -func (c *client) ServeHTTP(w http.ResponseWriter, r *http.Request) { - if err := c.InterceptRequest(r); err != nil { +func (proxy *Proxy) Intercept(i interceptor, w http.ResponseWriter, r *http.Request) { + if err := i.InterceptRequest(r); err != nil { _, isNoSuchContainer := err.(*docker.NoSuchContainer) switch { case isNoSuchContainer: @@ -41,7 +29,7 @@ func (c *client) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - conn, err := c.Dial() + conn, err := proxy.dial() if err != nil { http.Error(w, "Could not connect to target", http.StatusInternalServerError) Warning.Print(err) @@ -56,7 +44,7 @@ func (c *client) ServeHTTP(w http.ResponseWriter, r *http.Request) { Warning.Print("Error forwarding request: ", err) return } - err = c.InterceptResponse(resp) + err = i.InterceptResponse(resp) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) Warning.Print("Error intercepting response: ", err) diff --git a/proxy/proxy.go b/proxy/proxy.go index 1911fba8..fc9c86b4 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -95,7 +95,7 @@ func (proxy *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { default: i = &nullInterceptor{} } - newClient(proxy.dial, i).ServeHTTP(w, r) + proxy.Intercept(i, w, r) } func (proxy *Proxy) ListenAndServe() error {