From 5920927a52a83652eb594b5bc4299c9a9ca80413 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 27 May 2015 16:43:18 +0100 Subject: [PATCH] make the linter (almost) happy with ipam --- ipam/address/address.go | 5 ++--- ipam/allocator.go | 4 ++-- ipam/paxos/paxos.go | 3 +-- ipam/ring/ring.go | 6 +++--- ipam/space/space.go | 25 ++++++++++++------------- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ipam/address/address.go b/ipam/address/address.go index b9f47ac3..12718361 100644 --- a/ipam/address/address.go +++ b/ipam/address/address.go @@ -14,11 +14,10 @@ type Range struct { } func ParseIP(s string) (Address, error) { - if ip := net.ParseIP(s); ip == nil { - return 0, &net.ParseError{Type: "IP Address", Text: s} - } else { + if ip := net.ParseIP(s); ip != nil { return FromIP4(ip), nil } + return 0, &net.ParseError{Type: "IP Address", Text: s} } // FromIP4 converts an ipv4 address to our integer address type diff --git a/ipam/allocator.go b/ipam/allocator.go index d7ec53cb..0987e7e6 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -296,7 +296,7 @@ func (alloc *Allocator) AdminTakeoverRanges(peerNameOrNickname string) error { } delete(alloc.nicknames, peername) - err, newRanges := alloc.ring.Transfer(peername, alloc.ourName) + newRanges, err := alloc.ring.Transfer(peername, alloc.ourName) alloc.space.AddRanges(newRanges) resultChan <- err } @@ -320,7 +320,7 @@ func (alloc *Allocator) lookupPeername(name string) (router.PeerName, error) { // Restrict the peers in "nicknames" to those in the ring and our own func (alloc *Allocator) pruneNicknames() { ringPeers := alloc.ring.PeerNames() - for name, _ := range alloc.nicknames { + for name := range alloc.nicknames { if _, ok := ringPeers[name]; !ok && name != alloc.ourName { delete(alloc.nicknames, name) } diff --git a/ipam/paxos/paxos.go b/ipam/paxos/paxos.go index fd67283d..3224b974 100644 --- a/ipam/paxos/paxos.go +++ b/ipam/paxos/paxos.go @@ -255,7 +255,6 @@ func (node *Node) Consensus() (bool, AcceptedValue) { func (node *Node) String() string { if ok, val := node.Consensus(); ok { return fmt.Sprintf("Consensus reached with size %d", len(val.Value)) - } else { - return fmt.Sprintf("Nodes known: %d, Quorum size: %d", len(node.knows), node.quorum) } + return fmt.Sprintf("Nodes known: %d, Quorum size: %d", len(node.knows), node.quorum) } diff --git a/ipam/ring/ring.go b/ipam/ring/ring.go index 7590a3ce..f78df1db 100644 --- a/ipam/ring/ring.go +++ b/ipam/ring/ring.go @@ -461,7 +461,7 @@ func (r *Ring) PickPeerForTransfer() router.PeerName { // Transfer will mark all entries associated with 'from' peer as owned by 'to' peer // and return ranges indicating the new space we picked up -func (r *Ring) Transfer(from, to router.PeerName) (error, []address.Range) { +func (r *Ring) Transfer(from, to router.PeerName) ([]address.Range, error) { r.assertInvariants() defer r.assertInvariants() defer r.updateExportedVariables() @@ -479,10 +479,10 @@ func (r *Ring) Transfer(from, to router.PeerName) (error, []address.Range) { } if !found { - return ErrNotFound, nil + return nil, ErrNotFound } - return nil, r.splitRangesOverZero(newRanges) + return r.splitRangesOverZero(newRanges), nil } // Contains returns true if addr is in this ring diff --git a/ipam/space/space.go b/ipam/space/space.go index 2848a033..548d9e55 100644 --- a/ipam/space/space.go +++ b/ipam/space/space.go @@ -40,12 +40,11 @@ func (s *Space) Clear() { func (s *Space) Allocate() (bool, address.Address) { if len(s.free) == 0 { return false, 0 - } else { - res := s.free[0] - s.ours = add(s.ours, res, res+1) - s.free = subtract(s.free, res, res+1) - return true, res } + res := s.free[0] + s.ours = add(s.ours, res, res+1) + s.free = subtract(s.free, res, res+1) + return true, res } func (s *Space) Claim(addr address.Address) error { @@ -152,25 +151,25 @@ func subtract(addrs []address.Address, start address.Address, end address.Addres } func addSub(addrs []address.Address, start address.Address, end address.Address, sense int) []address.Address { - start_pos := firstGreaterOrEq(addrs, start) - end_pos := firstGreater(addrs[start_pos:], end) + start_pos + startPos := firstGreaterOrEq(addrs, start) + endPos := firstGreater(addrs[startPos:], end) + startPos - // Boundaries up to start_pos are unaffected - res := make([]address.Address, start_pos, len(addrs)+2) + // Boundaries up to startPos are unaffected + res := make([]address.Address, startPos, len(addrs)+2) copy(res, addrs) // Include start and end as new boundaries if they lie // outside/inside existing ranges (according to sense). - if start_pos&1 == sense { + if startPos&1 == sense { res = append(res, start) } - if end_pos&1 == sense { + if endPos&1 == sense { res = append(res, end) } - // Boundaries after end_pos are unaffected - return append(res, addrs[end_pos:]...) + // Boundaries after endPos are unaffected + return append(res, addrs[endPos:]...) } func (s *Space) String() string {