appease linter
This commit is contained in:
1 parent
d59594c6b0
commit
75d9e95b15
6 files changed
+36
-37
No files matched your search
+17
-18
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
+7
-7
@@ -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 {
|
||||
|
||||
+5
-5
@@ -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)
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
|
||||
+2
-2
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user