Kaynağa Gözat

Use gofmt with -s instead of goimports

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Vincent Demeester 9 yıl önce
ebeveyn
işleme
421a3ec5d7

+ 0 - 1
libnetwork/Dockerfile.build

@@ -8,6 +8,5 @@ RUN cd /go/src && mkdir -p golang.org/x && \
 RUN go get github.com/tools/godep \
 		github.com/golang/lint/golint \
 		golang.org/x/tools/cmd/vet \
-		golang.org/x/tools/cmd/goimports \
 		golang.org/x/tools/cmd/cover\
 		github.com/mattn/goveralls

+ 1 - 1
libnetwork/Makefile

@@ -53,7 +53,7 @@ check-code:
 
 check-format:
 	@echo "Checking format... "
-	test -z "$$(goimports -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
+	test -z "$$(gofmt -s -l . | grep -v Godeps/_workspace/src/ | tee /dev/stderr)"
 	@echo "Done checking format"
 
 run-tests:

+ 7 - 7
libnetwork/api/api_test.go

@@ -108,17 +108,17 @@ func createTestNetwork(t *testing.T, network string) (libnetwork.NetworkControll
 
 func getExposedPorts() []types.TransportPort {
 	return []types.TransportPort{
-		types.TransportPort{Proto: types.TCP, Port: uint16(5000)},
-		types.TransportPort{Proto: types.UDP, Port: uint16(400)},
-		types.TransportPort{Proto: types.TCP, Port: uint16(600)},
+		{Proto: types.TCP, Port: uint16(5000)},
+		{Proto: types.UDP, Port: uint16(400)},
+		{Proto: types.TCP, Port: uint16(600)},
 	}
 }
 
 func getPortMapping() []types.PortBinding {
 	return []types.PortBinding{
-		types.PortBinding{Proto: types.TCP, Port: uint16(230), HostPort: uint16(23000)},
-		types.PortBinding{Proto: types.UDP, Port: uint16(200), HostPort: uint16(22000)},
-		types.PortBinding{Proto: types.TCP, Port: uint16(120), HostPort: uint16(12000)},
+		{Proto: types.TCP, Port: uint16(230), HostPort: uint16(23000)},
+		{Proto: types.UDP, Port: uint16(200), HostPort: uint16(22000)},
+		{Proto: types.TCP, Port: uint16(120), HostPort: uint16(12000)},
 	}
 }
 
@@ -135,7 +135,7 @@ func TestSandboxOptionParser(t *testing.T) {
 	hp := "/etc/hosts"
 	rc := "/etc/resolv.conf"
 	dnss := []string{"8.8.8.8", "172.28.34.5"}
-	ehs := []extraHost{extraHost{Name: "extra1", Address: "172.28.9.1"}, extraHost{Name: "extra2", Address: "172.28.9.2"}}
+	ehs := []extraHost{{Name: "extra1", Address: "172.28.9.1"}, {Name: "extra2", Address: "172.28.9.2"}}
 
 	sb := sandboxCreate{
 		HostName:          hn,

+ 3 - 3
libnetwork/bitseq/sequence_test.go

@@ -1020,7 +1020,7 @@ func TestIsCorrupted(t *testing.T) {
 	// address reservation: last bit). This will allow an application using bitseq that runs a consistency
 	// check to detect and replace the 1.9.0/1 old vulnerable handle with the new one.
 	input := []*Handle{
-		&Handle{
+		{
 			id:         "LocalDefault/172.17.0.0/16",
 			bits:       65536,
 			unselected: 65412,
@@ -1055,7 +1055,7 @@ func TestIsCorrupted(t *testing.T) {
 				},
 			},
 		},
-		&Handle{
+		{
 			id:         "LocalDefault/172.17.0.0/16",
 			bits:       65536,
 			unselected: 65319,
@@ -1088,7 +1088,7 @@ func TestIsCorrupted(t *testing.T) {
 				},
 			},
 		},
-		&Handle{
+		{
 			id:         "LocalDefault/172.17.0.0/16",
 			bits:       65536,
 			unselected: 65456,

+ 1 - 1
libnetwork/cmd/dnet/dnet.go

@@ -278,7 +278,7 @@ func handleSignals(controller libnetwork.NetworkController) {
 	signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT}
 	signal.Notify(c, signals...)
 	go func() {
-		for _ = range c {
+		for range c {
 			controller.Stop()
 			os.Exit(0)
 		}

+ 4 - 4
libnetwork/driverapi/driverapi_test.go

@@ -15,8 +15,8 @@ func TestIPDataMarshalling(t *testing.T) {
 		Pool:         &net.IPNet{IP: net.IP{10, 10, 10, 8}, Mask: net.IPMask{255, 255, 255, 0}},
 		Gateway:      &net.IPNet{IP: net.IP{10, 10, 10, 254}, Mask: net.IPMask{255, 255, 255, 0}},
 		AuxAddresses: map[string]*net.IPNet{
-			"ip1": &net.IPNet{IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
-			"ip2": &net.IPNet{IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
+			"ip1": {IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
+			"ip2": {IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
 		},
 	}
 
@@ -59,8 +59,8 @@ func TestValidateAndIsV6(t *testing.T) {
 		Pool:    &net.IPNet{IP: net.IP{10, 10, 10, 8}, Mask: net.IPMask{255, 255, 255, 0}},
 		Gateway: &net.IPNet{IP: net.IP{10, 10, 10, 254}, Mask: net.IPMask{255, 255, 255, 0}},
 		AuxAddresses: map[string]*net.IPNet{
-			"ip1": &net.IPNet{IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
-			"ip2": &net.IPNet{IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
+			"ip1": {IP: net.IP{10, 10, 10, 1}, Mask: net.IPMask{255, 255, 255, 0}},
+			"ip2": {IP: net.IP{10, 10, 10, 2}, Mask: net.IPMask{255, 255, 255, 0}},
 		},
 	}
 

+ 11 - 11
libnetwork/drivers/bridge/bridge_test.go

@@ -59,7 +59,7 @@ func TestCreateFullOptions(t *testing.T) {
 	}
 
 	ipdList := []driverapi.IPAMData{
-		driverapi.IPAMData{
+		{
 			Pool:         bnw,
 			Gateway:      br,
 			AuxAddresses: map[string]*net.IPNet{DefaultGatewayV4AuxKey: defgw},
@@ -130,7 +130,7 @@ func TestCreateFullOptionsLabels(t *testing.T) {
 
 	ipdList := getIPv4Data(t)
 	ipd6List := []driverapi.IPAMData{
-		driverapi.IPAMData{
+		{
 			Pool: nwV6,
 			AuxAddresses: map[string]*net.IPNet{
 				DefaultGatewayV6AuxKey: gwV6,
@@ -552,17 +552,17 @@ func TestCreateLinkWithOptions(t *testing.T) {
 
 func getExposedPorts() []types.TransportPort {
 	return []types.TransportPort{
-		types.TransportPort{Proto: types.TCP, Port: uint16(5000)},
-		types.TransportPort{Proto: types.UDP, Port: uint16(400)},
-		types.TransportPort{Proto: types.TCP, Port: uint16(600)},
+		{Proto: types.TCP, Port: uint16(5000)},
+		{Proto: types.UDP, Port: uint16(400)},
+		{Proto: types.TCP, Port: uint16(600)},
 	}
 }
 
 func getPortMapping() []types.PortBinding {
 	return []types.PortBinding{
-		types.PortBinding{Proto: types.TCP, Port: uint16(230), HostPort: uint16(23000)},
-		types.PortBinding{Proto: types.UDP, Port: uint16(200), HostPort: uint16(22000)},
-		types.PortBinding{Proto: types.TCP, Port: uint16(120), HostPort: uint16(12000)},
+		{Proto: types.TCP, Port: uint16(230), HostPort: uint16(23000)},
+		{Proto: types.UDP, Port: uint16(200), HostPort: uint16(22000)},
+		{Proto: types.TCP, Port: uint16(120), HostPort: uint16(12000)},
 	}
 }
 
@@ -819,9 +819,9 @@ func TestSetDefaultGw(t *testing.T) {
 func TestCleanupIptableRules(t *testing.T) {
 	defer testutils.SetupTestOSContext(t)()
 	bridgeChain := []iptables.ChainInfo{
-		iptables.ChainInfo{Name: DockerChain, Table: iptables.Nat},
-		iptables.ChainInfo{Name: DockerChain, Table: iptables.Filter},
-		iptables.ChainInfo{Name: IsolationChain, Table: iptables.Filter},
+		{Name: DockerChain, Table: iptables.Nat},
+		{Name: DockerChain, Table: iptables.Filter},
+		{Name: IsolationChain, Table: iptables.Filter},
 	}
 	if _, _, _, err := setupIPChains(&configuration{EnableIPTables: true}); err != nil {
 		t.Fatalf("Error setting up ip chains: %v", err)

+ 3 - 3
libnetwork/drivers/bridge/link_test.go

@@ -8,9 +8,9 @@ import (
 
 func getPorts() []types.TransportPort {
 	return []types.TransportPort{
-		types.TransportPort{Proto: types.TCP, Port: uint16(5000)},
-		types.TransportPort{Proto: types.UDP, Port: uint16(400)},
-		types.TransportPort{Proto: types.TCP, Port: uint16(600)},
+		{Proto: types.TCP, Port: uint16(5000)},
+		{Proto: types.UDP, Port: uint16(400)},
+		{Proto: types.TCP, Port: uint16(600)},
 	}
 }
 

+ 14 - 14
libnetwork/etchosts/etchosts_test.go

@@ -152,15 +152,15 @@ func TestUpdateIgnoresPrefixedHostname(t *testing.T) {
 	defer os.Remove(file.Name())
 
 	if err := Build(file.Name(), "10.11.12.13", "testhostname", "testdomainname", []Record{
-		Record{
+		{
 			Hosts: "prefix",
 			IP:    "2.2.2.2",
 		},
-		Record{
+		{
 			Hosts: "prefixAndMore",
 			IP:    "3.3.3.3",
 		},
-		Record{
+		{
 			Hosts: "unaffectedHost",
 			IP:    "4.4.4.4",
 		},
@@ -209,11 +209,11 @@ func TestDeleteIgnoresPrefixedHostname(t *testing.T) {
 	}
 
 	if err := Add(file.Name(), []Record{
-		Record{
+		{
 			Hosts: "prefix",
 			IP:    "1.1.1.1",
 		},
-		Record{
+		{
 			Hosts: "prefixAndMore",
 			IP:    "2.2.2.2",
 		},
@@ -222,7 +222,7 @@ func TestDeleteIgnoresPrefixedHostname(t *testing.T) {
 	}
 
 	if err := Delete(file.Name(), []Record{
-		Record{
+		{
 			Hosts: "prefix",
 			IP:    "1.1.1.1",
 		},
@@ -274,7 +274,7 @@ func TestAdd(t *testing.T) {
 	}
 
 	if err := Add(file.Name(), []Record{
-		Record{
+		{
 			Hosts: "testhostname",
 			IP:    "2.2.2.2",
 		},
@@ -322,15 +322,15 @@ func TestDelete(t *testing.T) {
 	}
 
 	if err := Add(file.Name(), []Record{
-		Record{
+		{
 			Hosts: "testhostname1",
 			IP:    "1.1.1.1",
 		},
-		Record{
+		{
 			Hosts: "testhostname2",
 			IP:    "2.2.2.2",
 		},
-		Record{
+		{
 			Hosts: "testhostname3",
 			IP:    "3.3.3.3",
 		},
@@ -339,11 +339,11 @@ func TestDelete(t *testing.T) {
 	}
 
 	if err := Delete(file.Name(), []Record{
-		Record{
+		{
 			Hosts: "testhostname1",
 			IP:    "1.1.1.1",
 		},
-		Record{
+		{
 			Hosts: "testhostname3",
 			IP:    "3.3.3.3",
 		},
@@ -378,7 +378,7 @@ func TestConcurrentWrites(t *testing.T) {
 	}
 
 	if err := Add(file.Name(), []Record{
-		Record{
+		{
 			Hosts: "inithostname",
 			IP:    "172.17.0.1",
 		},
@@ -393,7 +393,7 @@ func TestConcurrentWrites(t *testing.T) {
 			defer wg.Done()
 
 			rec := []Record{
-				Record{
+				{
 					IP:    fmt.Sprintf("%d.%d.%d.%d", i, i, i, i),
 					Hosts: fmt.Sprintf("testhostname%d", i),
 				},

+ 3 - 3
libnetwork/hostdiscovery/hostdiscovery_test.go

@@ -40,7 +40,7 @@ func TestDiff(t *testing.T) {
 func TestAddedCallback(t *testing.T) {
 	hd := hostDiscovery{}
 	hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1"})
-	update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}, &discovery.Entry{Host: "2.2.2.2", Port: "0"}}
+	update := []*discovery.Entry{{Host: "1.1.1.1", Port: "0"}, {Host: "2.2.2.2", Port: "0"}}
 
 	added := false
 	removed := false
@@ -53,7 +53,7 @@ func TestAddedCallback(t *testing.T) {
 func TestRemovedCallback(t *testing.T) {
 	hd := hostDiscovery{}
 	hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
-	update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}}
+	update := []*discovery.Entry{{Host: "1.1.1.1", Port: "0"}}
 
 	added := false
 	removed := false
@@ -66,7 +66,7 @@ func TestRemovedCallback(t *testing.T) {
 func TestNoCallback(t *testing.T) {
 	hd := hostDiscovery{}
 	hd.nodes = mapset.NewSetFromSlice([]interface{}{"1.1.1.1", "2.2.2.2"})
-	update := []*discovery.Entry{&discovery.Entry{Host: "1.1.1.1", Port: "0"}, &discovery.Entry{Host: "2.2.2.2", Port: "0"}}
+	update := []*discovery.Entry{{Host: "1.1.1.1", Port: "0"}, {Host: "2.2.2.2", Port: "0"}}
 
 	added := false
 	removed := false

+ 12 - 12
libnetwork/libnetwork_internal_test.go

@@ -72,20 +72,20 @@ func TestNetworkMarshalling(t *testing.T) {
 			netlabel.MacAddress: "a:b:c:d:e:f",
 		},
 		ipamV4Config: []*IpamConf{
-			&IpamConf{
+			{
 				PreferredPool: "10.2.0.0/16",
 				SubPool:       "10.2.0.0/24",
 				Gateway:       "",
 				AuxAddresses:  nil,
 			},
-			&IpamConf{
+			{
 				PreferredPool: "10.2.0.0/16",
 				SubPool:       "10.2.1.0/24",
 				Gateway:       "10.2.1.254",
 			},
 		},
 		ipamV6Config: []*IpamConf{
-			&IpamConf{
+			{
 				PreferredPool: "abcd::/64",
 				SubPool:       "abcd:abcd:abcd:abcd:abcd::/80",
 				Gateway:       "abcd::29/64",
@@ -93,7 +93,7 @@ func TestNetworkMarshalling(t *testing.T) {
 			},
 		},
 		ipamV4Info: []*IpamInfo{
-			&IpamInfo{
+			{
 				PoolID: "ipoolverde123",
 				Meta: map[string]string{
 					netlabel.Gateway: "10.2.1.255/16",
@@ -108,7 +108,7 @@ func TestNetworkMarshalling(t *testing.T) {
 					AuxAddresses: nil,
 				},
 			},
-			&IpamInfo{
+			{
 				PoolID: "ipoolblue345",
 				Meta: map[string]string{
 					netlabel.Gateway: "10.2.1.255/16",
@@ -121,12 +121,12 @@ func TestNetworkMarshalling(t *testing.T) {
 					},
 					Gateway: &net.IPNet{IP: net.IP{10, 2, 1, 254}, Mask: net.IPMask{255, 255, 255, 0}},
 					AuxAddresses: map[string]*net.IPNet{
-						"ip3": &net.IPNet{IP: net.IP{10, 2, 1, 3}, Mask: net.IPMask{255, 255, 255, 0}},
-						"ip5": &net.IPNet{IP: net.IP{10, 2, 1, 55}, Mask: net.IPMask{255, 255, 255, 0}},
+						"ip3": {IP: net.IP{10, 2, 1, 3}, Mask: net.IPMask{255, 255, 255, 0}},
+						"ip5": {IP: net.IP{10, 2, 1, 55}, Mask: net.IPMask{255, 255, 255, 0}},
 					},
 				},
 			},
-			&IpamInfo{
+			{
 				PoolID: "weirdinfo",
 				IPAMData: driverapi.IPAMData{
 					Gateway: &net.IPNet{
@@ -137,7 +137,7 @@ func TestNetworkMarshalling(t *testing.T) {
 			},
 		},
 		ipamV6Info: []*IpamInfo{
-			&IpamInfo{
+			{
 				PoolID: "ipoolv6",
 				IPAMData: driverapi.IPAMData{
 					AddressSpace: "viola",
@@ -343,7 +343,7 @@ func TestAuxAddresses(t *testing.T) {
 
 	for _, i := range input {
 
-		n.ipamV4Config = []*IpamConf{&IpamConf{PreferredPool: i.masterPool, SubPool: i.subPool, AuxAddresses: i.auxAddresses}}
+		n.ipamV4Config = []*IpamConf{{PreferredPool: i.masterPool, SubPool: i.subPool, AuxAddresses: i.auxAddresses}}
 
 		err = n.ipamAllocate()
 
@@ -373,7 +373,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
 
 	// Test whether ipam state release is invoked  on network create failure from net driver
 	// by checking whether subsequent network creation requesting same gateway IP succeeds
-	ipamOpt := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{&IpamConf{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
+	ipamOpt := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.254"}}, nil, nil)
 	if _, err := c.NewNetwork(badDriverName, "badnet1", ipamOpt); err == nil {
 		t.Fatalf("bad network driver should have failed network creation")
 	}
@@ -397,7 +397,7 @@ func TestIpamReleaseOnNetDriverFailures(t *testing.T) {
 	}
 
 	// Now create good bridge network with different gateway
-	ipamOpt2 := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{&IpamConf{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.253"}}, nil, nil)
+	ipamOpt2 := NetworkOptionIpam(ipamapi.DefaultIPAM, "", []*IpamConf{{PreferredPool: "10.34.0.0/16", Gateway: "10.34.255.253"}}, nil, nil)
 	gnw, err = c.NewNetwork("bridge", "goodnet2", ipamOpt2)
 	if err != nil {
 		t.Fatal(err)

+ 7 - 7
libnetwork/libnetwork_test.go

@@ -276,8 +276,8 @@ func TestBridge(t *testing.T) {
 			"EnableIPMasquerade": true,
 		},
 	}
-	ipamV4ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "192.168.100.0/24", Gateway: "192.168.100.1"}}
-	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
+	ipamV4ConfList := []*libnetwork.IpamConf{{PreferredPool: "192.168.100.0/24", Gateway: "192.168.100.1"}}
+	ipamV6ConfList := []*libnetwork.IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
 
 	network, err := createTestNetwork(bridgeNetType, "testnetwork", netOption, ipamV4ConfList, ipamV6ConfList)
 	if err != nil {
@@ -327,8 +327,8 @@ func TestBridgeIpv6FromMac(t *testing.T) {
 			"EnableIPMasquerade": true,
 		},
 	}
-	ipamV4ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "192.168.100.0/24", Gateway: "192.168.100.1"}}
-	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
+	ipamV4ConfList := []*libnetwork.IpamConf{{PreferredPool: "192.168.100.0/24", Gateway: "192.168.100.1"}}
+	ipamV6ConfList := []*libnetwork.IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
 
 	network, err := controller.NewNetwork(bridgeNetType, "testipv6mac",
 		libnetwork.NetworkOptionGeneric(netOption),
@@ -566,7 +566,7 @@ func TestUnknownEndpoint(t *testing.T) {
 	option := options.Generic{
 		netlabel.GenericData: netOption,
 	}
-	ipamV4ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "192.168.100.0/24"}}
+	ipamV4ConfList := []*libnetwork.IpamConf{{PreferredPool: "192.168.100.0/24"}}
 
 	network, err := createTestNetwork(bridgeNetType, "testnetwork", option, ipamV4ConfList, nil)
 	if err != nil {
@@ -1012,7 +1012,7 @@ func TestEndpointJoin(t *testing.T) {
 			"EnableIPMasquerade": true,
 		},
 	}
-	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
+	ipamV6ConfList := []*libnetwork.IpamConf{{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
 	n1, err := controller.NewNetwork(bridgeNetType, "testnetwork1",
 		libnetwork.NetworkOptionGeneric(netOption),
 		libnetwork.NetworkOptionEnableIPv6(true),
@@ -1729,7 +1729,7 @@ func TestEnableIPv6(t *testing.T) {
 			"BridgeName": "testnetwork",
 		},
 	}
-	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe99::/64", Gateway: "fe99::9"}}
+	ipamV6ConfList := []*libnetwork.IpamConf{{PreferredPool: "fe99::/64", Gateway: "fe99::9"}}
 
 	n, err := createTestNetwork("bridge", "testnetwork", netOption, nil, ipamV6ConfList)
 	if err != nil {

+ 1 - 1
libnetwork/network.go

@@ -1004,7 +1004,7 @@ func (n *network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
 		if ipVer == 6 {
 			return nil
 		}
-		*cfgList = []*IpamConf{&IpamConf{}}
+		*cfgList = []*IpamConf{{}}
 	}
 
 	*infoList = make([]*IpamInfo, len(*cfgList))

+ 1 - 1
libnetwork/portmapper/proxy.go

@@ -85,7 +85,7 @@ func handleStopSignals(p proxy.Proxy) {
 	s := make(chan os.Signal, 10)
 	signal.Notify(s, os.Interrupt, syscall.SIGTERM, syscall.SIGSTOP)
 
-	for _ = range s {
+	for range s {
 		p.Close()
 
 		os.Exit(0)