Skip to content

Commit af5e370

Browse files
author
Flavio Crisciani
committed
Add gosimple check
Add the gosimple tool check in the Makefile Fix all the issues identified Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
1 parent d280b98 commit af5e370

File tree

11 files changed

+26
-57
lines changed

11 files changed

+26
-57
lines changed

libnetwork/Dockerfile.build

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ RUN go get github.com/tools/godep \
66
golang.org/x/tools/cmd/cover \
77
github.com/mattn/goveralls \
88
github.com/gordonklaus/ineffassign \
9-
github.com/client9/misspell/cmd/misspell
9+
github.com/client9/misspell/cmd/misspell \
10+
honnef.co/go/tools/cmd/gosimple

libnetwork/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all all-local build build-local clean cross cross-local vet lint misspell check check-code check-format run-tests integration-tests check-local coveralls circle-ci-cross circle-ci-build circle-ci-check circle-ci
1+
.PHONY: all all-local build build-local clean cross cross-local gosimple vet lint misspell check check-code check-format run-tests integration-tests check-local coveralls circle-ci-cross circle-ci-build circle-ci-check circle-ci
22
SHELL=/bin/bash
33
build_image=libnetworkbuild
44
dockerargs = --privileged -v $(shell pwd):/go/src/github.com/docker/libnetwork -w /go/src/github.com/docker/libnetwork
@@ -64,7 +64,7 @@ cross-local:
6464
check: ${build_image}.created
6565
@${docker} ./wrapmake.sh check-local
6666

67-
check-code: lint vet ineffassign
67+
check-code: lint gosimple vet ineffassign
6868

6969
check-format: fmt misspell
7070

@@ -153,6 +153,10 @@ ineffassign: ## run ineffassign
153153
@echo "🐳 $@"
154154
@test -z "$$(ineffassign . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)"
155155

156+
gosimple: ## run gosimple
157+
@echo "🐳 $@"
158+
@test -z "$$(gosimple . | grep -v vendor/ | grep -v ".pb.go:" | grep -v ".mock.go" | tee /dev/stderr)"
159+
156160
# CircleCI's Docker fails when cleaning up using the --rm flag
157161
# The following targets are a workaround for this
158162
circle-ci-cross: ${build_image}.created

libnetwork/agent.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,11 @@ func (c *controller) agentClose() {
383383

384384
agent.Lock()
385385
for _, cancelFuncs := range agent.driverCancelFuncs {
386-
for _, cancel := range cancelFuncs {
387-
cancelList = append(cancelList, cancel)
388-
}
386+
cancelList = append(cancelList, cancelFuncs...)
389387
}
390388

391389
// Add also the cancel functions for the network db
392-
for _, cancel := range agent.coreCancelFuncs {
393-
cancelList = append(cancelList, cancel)
394-
}
390+
cancelList = append(cancelList, agent.coreCancelFuncs...)
395391
agent.Unlock()
396392

397393
for _, cancel := range cancelList {

libnetwork/endpoint_info.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,7 @@ func (epi *endpointInterface) CopyTo(dstEpi *endpointInterface) error {
154154
dstEpi.v6PoolID = epi.v6PoolID
155155
if len(epi.llAddrs) != 0 {
156156
dstEpi.llAddrs = make([]*net.IPNet, 0, len(epi.llAddrs))
157-
for _, ll := range epi.llAddrs {
158-
dstEpi.llAddrs = append(dstEpi.llAddrs, ll)
159-
}
157+
dstEpi.llAddrs = append(dstEpi.llAddrs, epi.llAddrs...)
160158
}
161159

162160
for _, route := range epi.routes {

libnetwork/libnetwork_linux_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,7 @@ func runParallelTests(t *testing.T, thrNumber int) {
903903
}
904904

905905
if thrNumber != first {
906-
select {
907-
case <-start:
908-
}
906+
<-start
909907

910908
thrdone := make(chan struct{})
911909
done <- thrdone
@@ -972,9 +970,7 @@ func runParallelTests(t *testing.T, thrNumber int) {
972970
}
973971
if thrNumber == first {
974972
for thrdone := range done {
975-
select {
976-
case <-thrdone:
977-
}
973+
<-thrdone
978974
}
979975

980976
testns.Close()

libnetwork/libnetwork_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ func createController() error {
6464
return err
6565
}
6666
controller, err = libnetwork.New(append(cfgOptions, config.OptionDriverConfig(bridgeNetType, genericOption))...)
67-
if err != nil {
68-
return err
69-
}
70-
71-
return nil
67+
return err
7268
}
7369

7470
func createTestNetwork(networkType, networkName string, netOption options.Generic, ipamV4Configs, ipamV6Configs []*libnetwork.IpamConf) (libnetwork.Network, error) {

libnetwork/network.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -434,15 +434,11 @@ func (n *network) applyConfigurationTo(to *network) error {
434434
}
435435
if len(n.ipamV4Config) > 0 {
436436
to.ipamV4Config = make([]*IpamConf, 0, len(n.ipamV4Config))
437-
for _, v4conf := range n.ipamV4Config {
438-
to.ipamV4Config = append(to.ipamV4Config, v4conf)
439-
}
437+
to.ipamV4Config = append(to.ipamV4Config, n.ipamV4Config...)
440438
}
441439
if len(n.ipamV6Config) > 0 {
442440
to.ipamV6Config = make([]*IpamConf, 0, len(n.ipamV6Config))
443-
for _, v6conf := range n.ipamV6Config {
444-
to.ipamV6Config = append(to.ipamV6Config, v6conf)
445-
}
441+
to.ipamV6Config = append(to.ipamV6Config, n.ipamV6Config...)
446442
}
447443
if len(n.generic) > 0 {
448444
to.generic = options.Generic{}
@@ -873,8 +869,7 @@ func (n *network) resolveDriver(name string, load bool) (driverapi.Driver, *driv
873869
d, cap := c.drvRegistry.Driver(name)
874870
if d == nil {
875871
if load {
876-
var err error
877-
err = c.loadDriver(name)
872+
err := c.loadDriver(name)
878873
if err != nil {
879874
return nil, nil, err
880875
}
@@ -1451,11 +1446,7 @@ func (n *network) ipamAllocate() error {
14511446
}
14521447

14531448
err = n.ipamAllocateVersion(6, ipam)
1454-
if err != nil {
1455-
return err
1456-
}
1457-
1458-
return nil
1449+
return err
14591450
}
14601451

14611452
func (n *network) requestPoolHelper(ipam ipamapi.Ipam, addressSpace, preferredPool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) {
@@ -1654,9 +1645,7 @@ func (n *network) getIPInfo(ipVer int) []*IpamInfo {
16541645
}
16551646
l := make([]*IpamInfo, 0, len(info))
16561647
n.Lock()
1657-
for _, d := range info {
1658-
l = append(l, d)
1659-
}
1648+
l = append(l, info...)
16601649
n.Unlock()
16611650
return l
16621651
}
@@ -1870,7 +1859,7 @@ func (n *network) ResolveName(req string, ipType int) ([]net.IP, bool) {
18701859
// the docker network domain. If the network is not v6 enabled
18711860
// set ipv6Miss to filter the DNS query from going to external
18721861
// resolvers.
1873-
if ok && n.enableIPv6 == false {
1862+
if ok && !n.enableIPv6 {
18741863
ipv6Miss = true
18751864
}
18761865
ipSet, ok = sr.svcIPv6Map.Get(req)

libnetwork/resolver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
446446
defer co.Close()
447447

448448
// limits the number of outstanding concurrent queries.
449-
if r.forwardQueryStart() == false {
449+
if !r.forwardQueryStart() {
450450
old := r.tStamp
451451
r.tStamp = time.Now()
452452
if r.tStamp.Sub(old) > logInterval {

libnetwork/sandbox.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ func (sb *sandbox) resolveName(req string, networkName string, epList []*endpoin
621621
func (sb *sandbox) SetKey(basePath string) error {
622622
start := time.Now()
623623
defer func() {
624-
logrus.Debugf("sandbox set key processing took %s for container %s", time.Now().Sub(start), sb.ContainerID())
624+
logrus.Debugf("sandbox set key processing took %s for container %s", time.Since(start), sb.ContainerID())
625625
}()
626626

627627
if basePath == "" {
@@ -773,9 +773,7 @@ func (sb *sandbox) restoreOslSandbox() error {
773773
}
774774
Ifaces[fmt.Sprintf("%s+%s", i.srcName, i.dstPrefix)] = ifaceOptions
775775
if joinInfo != nil {
776-
for _, r := range joinInfo.StaticRoutes {
777-
routes = append(routes, r)
778-
}
776+
routes = append(routes, joinInfo.StaticRoutes...)
779777
}
780778
if ep.needResolver() {
781779
sb.startResolver(true)
@@ -789,11 +787,7 @@ func (sb *sandbox) restoreOslSandbox() error {
789787

790788
// restore osl sandbox
791789
err := sb.osSbox.Restore(Ifaces, routes, gwep.joinInfo.gw, gwep.joinInfo.gw6)
792-
if err != nil {
793-
return err
794-
}
795-
796-
return nil
790+
return err
797791
}
798792

799793
func (sb *sandbox) populateNetworkResources(ep *endpoint) error {
@@ -958,9 +952,7 @@ func (sb *sandbox) joinLeaveStart() {
958952
joinLeaveDone := sb.joinLeaveDone
959953
sb.Unlock()
960954

961-
select {
962-
case <-joinLeaveDone:
963-
}
955+
<-joinLeaveDone
964956

965957
sb.Lock()
966958
}

libnetwork/sandbox_externalkey_unix.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func processSetKeyReexec() {
5252
controllerID := os.Args[2]
5353

5454
err = SetExternalKey(controllerID, containerID, fmt.Sprintf("/proc/%d/ns/net", state.Pid))
55-
return
5655
}
5756

5857
// SetExternalKey provides a convenient way to set an External key to a sandbox

0 commit comments

Comments
 (0)