From 75d9e95b1545450f2da1ac189308814e3660dd69 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Sat, 2 Jan 2016 12:35:10 +0000 Subject: [PATCH] appease linter --- api/weaveapi.go | 35 +++++++++++++++++------------------ common/docker/client.go | 6 +++--- common/odp/odp.go | 14 +++++++------- mesh/gossip_test.go | 10 +++++----- prog/weaver/main.go | 4 ++-- proxy/proxy.go | 4 ++-- 6 files changed, 36 insertions(+), 37 deletions(-) diff --git a/api/weaveapi.go b/api/weaveapi.go index 8be6b334..d721deff 100644 --- a/api/weaveapi.go +++ b/api/weaveapi.go @@ -13,24 +13,24 @@ import ( ) const ( - WeaveHttpPort = 6784 + WeaveHTTPPort = 6784 ) type Client struct { - baseUrl string + baseURL string resolve func() (string, error) } func (client *Client) httpVerb(verb string, url string, values url.Values) (string, error) { - baseUrl := client.baseUrl + baseURL := client.baseURL if client.resolve != nil { addr, err := client.resolve() if err != nil { return "", err } - baseUrl = fmt.Sprintf("http://%s:%d", addr, WeaveHttpPort) + baseURL = fmt.Sprintf("http://%s:%d", addr, WeaveHTTPPort) } - url = baseUrl + url + url = baseURL + url Log.Debugf("weave %s to %s with %v", verb, url, values) var body io.Reader if values != nil { @@ -43,24 +43,23 @@ func (client *Client) httpVerb(verb string, url string, values url.Values) (stri if values != nil { req.Header.Set("Content-Type", "application/x-www-form-urlencoded") } - if resp, err := http.DefaultClient.Do(req); err != nil { + resp, err := http.DefaultClient.Do(req) + if err != nil { return "", err - } else { - defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return "", err - } - if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent { - return string(body), nil - } else { - return "", errors.New(resp.Status + ": " + string(body)) - } } + defer resp.Body.Close() + rbody, err := ioutil.ReadAll(resp.Body) + if err != nil { + return "", err + } + if resp.StatusCode == http.StatusOK || resp.StatusCode == http.StatusNoContent { + return string(rbody), nil + } + return "", errors.New(resp.Status + ": " + string(rbody)) } func NewClient(addr string) *Client { - return &Client{baseUrl: fmt.Sprintf("http://%s:%d", addr, WeaveHttpPort)} + return &Client{baseURL: fmt.Sprintf("http://%s:%d", addr, WeaveHTTPPort)} } func NewClientWithResolver(resolver func() (string, error)) *Client { diff --git a/common/docker/client.go b/common/docker/client.go index 86cb9dd7..5bd04f3f 100644 --- a/common/docker/client.go +++ b/common/docker/client.go @@ -63,11 +63,11 @@ func (c *Client) checkWorking() error { } func (c *Client) Info() string { - if env, err := c.Version(); err != nil { + env, err := c.Version() + if err != nil { return fmt.Sprintf("Docker API error: %s", err) - } else { - return fmt.Sprintf("Docker API on %s: %v", c.Endpoint(), env) } + return fmt.Sprintf("Docker API on %s: %v", c.Endpoint(), env) } // AddObserver adds an observer for docker events diff --git a/common/odp/odp.go b/common/odp/odp.go index 53b481ff..f6689fee 100644 --- a/common/odp/odp.go +++ b/common/odp/odp.go @@ -10,28 +10,28 @@ import ( // ODP admin functionality -func CreateDatapath(dpname string) (err error, supported bool) { +func CreateDatapath(dpname string) (supported bool, err error) { dpif, err := odp.NewDpif() if err != nil { if odp.IsKernelLacksODPError(err) { - return nil, false + return false, nil } - return err, true + return true, err } defer dpif.Close() dp, err := dpif.CreateDatapath(dpname) if err != nil && !odp.IsDatapathNameAlreadyExistsError(err) { - return err, true + return true, err } // Pick an ephemeral port number to use in probing for vxlan // support. udpconn, err := net.ListenUDP("udp4", nil) if err != nil { - return err, true + return true, err } // we leave the UDP socket open, so creating a vxlan vport on @@ -43,7 +43,7 @@ func CreateDatapath(dpname string) (err error, supported bool) { if nlerr, ok := err.(odp.NetlinkError); ok { if syscall.Errno(nlerr) == syscall.EAFNOSUPPORT { dp.Delete() - return fmt.Errorf("kernel does not have Open vSwitch VXLAN support"), false + return false, fmt.Errorf("kernel does not have Open vSwitch VXLAN support") } } @@ -52,7 +52,7 @@ func CreateDatapath(dpname string) (err error, supported bool) { } udpconn.Close() - return nil, true + return true, nil } func DeleteDatapath(dpname string) error { diff --git a/mesh/gossip_test.go b/mesh/gossip_test.go index 119961a8..a2bf4497 100644 --- a/mesh/gossip_test.go +++ b/mesh/gossip_test.go @@ -11,7 +11,7 @@ import ( // TODO test gossip unicast; atm we only test topology gossip and // surrogates, neither of which employ unicast. -type mockGossipConnection struct { +type MockGossipConnection struct { RemoteConnection dest *Router start chan struct{} @@ -24,12 +24,12 @@ func NewTestRouter(name string) *Router { return router } -func (conn *mockGossipConnection) SendProtocolMsg(protocolMsg ProtocolMsg) error { +func (conn *MockGossipConnection) SendProtocolMsg(protocolMsg ProtocolMsg) error { <-conn.start return conn.dest.handleGossip(protocolMsg.tag, protocolMsg.msg) } -func (conn *mockGossipConnection) Start() { +func (conn *MockGossipConnection) Start() { close(conn.start) } @@ -50,12 +50,12 @@ func AddTestGossipConnection(r1, r2 *Router) { c2.Start() } -func (router *Router) NewTestGossipConnection(r *Router) *mockGossipConnection { +func (router *Router) NewTestGossipConnection(r *Router) *MockGossipConnection { to := r.Ourself.Peer toPeer := NewPeer(to.Name, to.NickName, to.UID, 0, to.ShortID) toPeer = router.Peers.FetchWithDefault(toPeer) // Has side-effect of incrementing refcount - conn := &mockGossipConnection{ + conn := &MockGossipConnection{ RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, r, make(chan struct{})} router.Ourself.handleAddConnection(conn) router.Ourself.handleConnectionEstablished(conn) diff --git a/prog/weaver/main.go b/prog/weaver/main.go index ba09998a..f264198e 100644 --- a/prog/weaver/main.go +++ b/prog/weaver/main.go @@ -130,8 +130,8 @@ func main() { os.Exit(0) case createDatapath: - err, odp_supported := odp.CreateDatapath(datapathName) - if !odp_supported { + odpSupported, err := odp.CreateDatapath(datapathName) + if !odpSupported { if err != nil { Log.Error(err) } diff --git a/proxy/proxy.go b/proxy/proxy.go index 9dfb7972..a5952dd5 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -94,9 +94,9 @@ func NewProxy(c Config) (*Proxy, error) { client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18") if err != nil { return nil, err - } else { - Log.Info(client.Info()) } + Log.Info(client.Info()) + p.client = client.Client if !p.WithoutDNS {