Skip to content

Commit

Permalink
golint: drop remaining else statement followed by return
Browse files Browse the repository at this point in the history
This is a follow up to 777cddb (golint: drop some else statement followed
by return, 2017-03-17). These were removed previously because they broke the
build, they are now reworked to not introduce any new errors. After this there
should be no more warnings like the following

... if block ends with a return statement, so drop this else and outdent its
    block (golint)

Related-to: #153 (Resolve golint warnings)
Signed-off-by: Alexander Alemayhu <alexander@alemayhu.com>
  • Loading branch information
aalemayhu authored and aanm committed Mar 18, 2017
1 parent fbc8b5c commit 3ac1140
Show file tree
Hide file tree
Showing 16 changed files with 153 additions and 156 deletions.
8 changes: 4 additions & 4 deletions bpf/lbmap/ipv4.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func (s *Service4Value) SetCount(count int) { s.Count = uint16(count) }
func (s *Service4Value) GetCount() int { return int(s.Count) }
func (s *Service4Value) SetRevNat(id int) { s.RevNat = uint16(id) }
func (s *Service4Value) SetAddress(ip net.IP) error {
if ip4 := ip.To4(); ip4 == nil {
ip4 := ip.To4()
if ip4 == nil {
return fmt.Errorf("Not an IPv4 address")
} else {
copy(s.Address[:], ip4)
return nil
}
copy(s.Address[:], ip4)
return nil
}

func (v *Service4Value) Convert() ServiceValue {
Expand Down
32 changes: 16 additions & 16 deletions cilium/cmd/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ func loadPolicy(name string) (*policy.Node, error) {
continue
}

if p, err := loadPolicyFile(filepath.Join(name, f.Name())); err != nil {
p, err := loadPolicyFile(filepath.Join(name, f.Name()))
if err != nil {
return nil, err
} else {
if node != nil {
if _, err := node.Merge(p); err != nil {
return nil, fmt.Errorf("Error: %s: %s", f.Name(), err)
}
} else {
node = p
}
if node != nil {
if _, err := node.Merge(p); err != nil {
return nil, fmt.Errorf("Error: %s: %s", f.Name(), err)
}
} else {
node = p
}
}

Expand All @@ -199,16 +199,16 @@ func loadPolicy(name string) (*policy.Node, error) {
continue
}
subpath := filepath.Join(name, f.Name())
if p, err := loadPolicy(subpath); err != nil {
p, err := loadPolicy(subpath)
if err != nil {
return nil, err
} else {
if p.Name == "" {
return nil, fmt.Errorf("Policy node import from %s did not derive a name",
subpath)
}

node.AddChild(p.Name, p)
}
if p.Name == "" {
return nil, fmt.Errorf("Policy node import from %s did not derive a name",
subpath)
}

node.AddChild(p.Name, p)
}
}

Expand Down
12 changes: 6 additions & 6 deletions common/addressing/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func NewCiliumIPv6(address string) (CiliumIPv6, error) {
// As result of ParseIP, ip is either a valid IPv6 or IPv4 address. net.IP
// represents both versions on 16 bytes, so a more reliable way to tell
// IPv4 and IPv6 apart is to see if it fits 4 bytes
if ip4 := ip.To4(); ip4 != nil {
ip4 := ip.To4()
if ip4 != nil {
return nil, fmt.Errorf("Not an IPv6 address: %s", address)
} else {
return DeriveCiliumIPv6(ip.To16()), nil
}
return DeriveCiliumIPv6(ip.To16()), nil
}

func DeriveCiliumIPv6(src net.IP) CiliumIPv6 {
Expand Down Expand Up @@ -184,11 +184,11 @@ func NewCiliumIPv4(address string) (CiliumIPv4, error) {
}
}

if ip4 := ip.To4(); ip4 == nil {
ip4 := ip.To4()
if ip4 == nil {
return nil, fmt.Errorf("Not an IPv4 address")
} else {
return DeriveCiliumIPv4(ip4), nil
}
return DeriveCiliumIPv4(ip4), nil
}

func DeriveCiliumIPv4(src net.IP) CiliumIPv4 {
Expand Down
56 changes: 28 additions & 28 deletions common/plugins/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,42 +58,42 @@ func (a ByMask) Swap(i, j int) {

// Returns IPv6 routes to be installed in endpoint's networking namespace
func IPv6Routes(addr *models.NodeAddressing) ([]Route, error) {
if ip := net.ParseIP(addr.IPV6.IP); ip == nil {
ip := net.ParseIP(addr.IPV6.IP)
if ip == nil {
return []Route{}, fmt.Errorf("Invalid IP address: %s", addr.IPV6.IP)
} else {
return []Route{
{
Prefix: net.IPNet{
IP: ip,
Mask: addressing.ContainerIPv6Mask,
},
},
{
Prefix: addressing.IPv6DefaultRoute,
Nexthop: &ip,
},
}, nil
}
return []Route{
{
Prefix: net.IPNet{
IP: ip,
Mask: addressing.ContainerIPv6Mask,
},
},
{
Prefix: addressing.IPv6DefaultRoute,
Nexthop: &ip,
},
}, nil
}

// Returns IPv4 routes to be installed in endpoint's networking namespace
func IPv4Routes(addr *models.NodeAddressing) ([]Route, error) {
if ip := net.ParseIP(addr.IPV4.IP); ip == nil {
ip := net.ParseIP(addr.IPV4.IP)
if ip == nil {
return []Route{}, fmt.Errorf("Invalid IP address: %s", addr.IPV4.IP)
} else {
return []Route{
{
Prefix: net.IPNet{
IP: ip,
Mask: addressing.ContainerIPv4Mask,
},
},
{
Prefix: addressing.IPv4DefaultRoute,
Nexthop: &ip,
},
}, nil
}
return []Route{
{
Prefix: net.IPNet{
IP: ip,
Mask: addressing.ContainerIPv4Mask,
},
},
{
Prefix: addressing.IPv4DefaultRoute,
Nexthop: &ip,
},
}, nil
}

func SufficientAddressing(addr *models.NodeAddressing) error {
Expand Down
12 changes: 6 additions & 6 deletions daemon/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func (d *Daemon) AllocateIP(ip net.IP) *apierror.ApiError {
}

func (d *Daemon) allocateIP(ipAddr string) *apierror.ApiError {
if ip := net.ParseIP(ipAddr); ip == nil {
ip := net.ParseIP(ipAddr)
if ip == nil {
return apierror.New(PostIPAMIPInvalidCode, "Invalid IP address: %s", ipAddr)
} else {
return d.AllocateIP(ip)
}
return d.AllocateIP(ip)
}

func (d *Daemon) ReleaseIP(ip net.IP) *apierror.ApiError {
Expand Down Expand Up @@ -88,11 +88,11 @@ func (d *Daemon) ReleaseIP(ip net.IP) *apierror.ApiError {
}

func (d *Daemon) releaseIP(ipAddr string) *apierror.ApiError {
if ip := net.ParseIP(ipAddr); ip == nil {
ip := net.ParseIP(ipAddr)
if ip == nil {
return apierror.New(DeleteIPAMIPInvalidCode, "Invalid IP address: %s", ipAddr)
} else {
return d.ReleaseIP(ip)
}
return d.ReleaseIP(ip)
}

type postIPAM struct {
Expand Down
38 changes: 19 additions & 19 deletions daemon/loadbalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ func (h *putServiceID) Handle(params PutServiceIDParams) middleware.Responder {

backends := []types.L3n4Addr{}
for _, v := range params.Config.BackendAddresses {
if b, err := types.NewL3n4AddrFromBackendModel(v); err != nil {
b, err := types.NewL3n4AddrFromBackendModel(v)
if err != nil {
return apierror.Error(PutServiceIDInvalidBackendCode, err)
} else {
backends = append(backends, *b)
}
backends = append(backends, *b)
}

revnat := false
Expand Down Expand Up @@ -200,11 +200,11 @@ func (d *Daemon) svcDeleteByFrontend(frontend *types.L3n4Addr) error {
d.loadBalancer.BPFMapMU.Lock()
defer d.loadBalancer.BPFMapMU.Unlock()

if svc, ok := d.loadBalancer.SVCMap[frontend.SHA256Sum()]; !ok {
svc, ok := d.loadBalancer.SVCMap[frontend.SHA256Sum()]
if !ok {
return fmt.Errorf("Service frontend not found %+v", frontend)
} else {
return d.svcDelete(&svc)
}
return d.svcDelete(&svc)
}

func (d *Daemon) svcDelete(svc *types.LBSVC) error {
Expand Down Expand Up @@ -253,20 +253,20 @@ func (d *Daemon) svcGetBySHA256Sum(feL3n4SHA256Sum string) *types.LBSVC {
d.loadBalancer.BPFMapMU.RLock()
defer d.loadBalancer.BPFMapMU.RUnlock()

if v, ok := d.loadBalancer.SVCMap[feL3n4SHA256Sum]; !ok {
v, ok := d.loadBalancer.SVCMap[feL3n4SHA256Sum]
if !ok {
return nil
} else {
// We will move the slice from the loadbalancer map which have a mutex. If
// we don't copy the slice we might risk changing memory that should be
// locked.
beL3n4AddrCpy := []types.L3n4Addr{}
for _, v := range v.BES {
beL3n4AddrCpy = append(beL3n4AddrCpy, v)
}
return &types.LBSVC{
FE: *v.FE.DeepCopy(),
BES: beL3n4AddrCpy,
}
}
// We will move the slice from the loadbalancer map which have a mutex. If
// we don't copy the slice we might risk changing memory that should be
// locked.
beL3n4AddrCpy := []types.L3n4Addr{}
for _, v := range v.BES {
beL3n4AddrCpy = append(beL3n4AddrCpy, v)
}
return &types.LBSVC{
FE: *v.FE.DeepCopy(),
BES: beL3n4AddrCpy,
}
}

Expand Down
14 changes: 7 additions & 7 deletions daemon/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ func (h *getPolicyPath) Handle(params GetPolicyPathParams) middleware.Responder
d.policy.Mutex.RLock()
defer d.policy.Mutex.RUnlock()

if node, _ := d.policy.Lookup(params.Path); node == nil {
node, _ := d.policy.Lookup(params.Path)
if node == nil {
return NewGetPolicyPathNotFound()
} else {
return NewGetPolicyPathOK().WithPayload(models.PolicyTree(node.JSONMarshal()))
}
return NewGetPolicyPathOK().WithPayload(models.PolicyTree(node.JSONMarshal()))
}

func (d *Daemon) PolicyInit() error {
Expand All @@ -295,12 +295,12 @@ func (d *Daemon) PolicyInit() error {
return fmt.Errorf("Could not create policy BPF map '%s': %s", policyMapPath, err)
}

if c := d.consumableCache.GetOrCreate(v, secLbl); c == nil {
c := d.consumableCache.GetOrCreate(v, secLbl)
if c == nil {
return fmt.Errorf("Unable to initialize consumable for %v", secLbl)
} else {
d.consumableCache.AddReserved(c)
c.AddMap(policyMap)
}
d.consumableCache.AddReserved(c)
c.AddMap(policyMap)
}

return nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/client/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func (c *Client) EndpointList() ([]*models.Endpoint, error) {
// Get endpoint by ID
func (c *Client) EndpointGet(id string) (*models.Endpoint, error) {
params := endpoint.NewGetEndpointIDParams().WithID(id)
if resp, err := c.Endpoint.GetEndpointID(params); err != nil {
resp, err := c.Endpoint.GetEndpointID(params)
if err != nil {
return nil, err
} else {
return resp.Payload, nil
}
return resp.Payload, nil
}

// Create endpoint
Expand Down Expand Up @@ -64,11 +64,11 @@ func (c *Client) EndpointDelete(id string) error {
// Get endpoint configuration
func (c *Client) EndpointConfigGet(id string) (*models.Configuration, error) {
params := endpoint.NewGetEndpointIDConfigParams().WithID(id)
if resp, err := c.Endpoint.GetEndpointIDConfig(params); err != nil {
resp, err := c.Endpoint.GetEndpointIDConfig(params)
if err != nil {
return nil, err
} else {
return resp.Payload, nil
}
return resp.Payload, nil
}

// Modify endpoint configuration
Expand All @@ -85,11 +85,11 @@ func (c *Client) EndpointConfigPatch(id string, cfg models.ConfigurationMap) err
// Get endpoint label configuration
func (c *Client) EndpointLabelsGet(id string) (*models.LabelConfiguration, error) {
params := endpoint.NewGetEndpointIDLabelsParams().WithID(id)
if resp, err := c.Endpoint.GetEndpointIDLabels(params); err != nil {
resp, err := c.Endpoint.GetEndpointIDLabels(params)
if err != nil {
return nil, err
} else {
return resp.Payload, nil
}
return resp.Payload, nil
}

// Modify endpoint label configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/client/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (
func (c *Client) IdentityGet(id string) (*models.Identity, error) {
params := policy.NewGetIdentityIDParams().WithID(id)

if resp, err := c.Policy.GetIdentityID(params); err != nil {
resp, err := c.Policy.GetIdentityID(params)
if err != nil {
return nil, err
} else {
return resp.Payload, nil
}
return resp.Payload, nil
}

0 comments on commit 3ac1140

Please sign in to comment.