Browse Source

all: Avoid trivial uses of Sprintf

Use the string concatenation operator instead of using Sprintf for
simple string concatenation. This is usually easier to read, and allows
the compiler to detect problems with the type or number of operands,
which would be runtime errors with Sprintf.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
Aaron Lehmann 8 years ago
parent
commit
cc0b7e6aad

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

@@ -474,7 +474,7 @@ func verifyV4INCEntries(networks map[string]*bridgeNetwork, numEntries int, t *t
 			if x == y {
 			if x == y {
 				continue
 				continue
 			}
 			}
-			re := regexp.MustCompile(fmt.Sprintf("%s %s", x.config.BridgeName, y.config.BridgeName))
+			re := regexp.MustCompile(x.config.BridgeName + " " + y.config.BridgeName)
 			matches := re.FindAllString(string(out[:]), -1)
 			matches := re.FindAllString(string(out[:]), -1)
 			if len(matches) != 1 {
 			if len(matches) != 1 {
 				t.Fatalf("Cannot find expected inter-network isolation rules in IP Tables:\n%s", string(out[:]))
 				t.Fatalf("Cannot find expected inter-network isolation rules in IP Tables:\n%s", string(out[:]))

+ 1 - 1
libnetwork/drivers/ipvlan/ipvlan_setup.go

@@ -201,5 +201,5 @@ func delDummyLink(linkName string) error {
 
 
 // getDummyName returns the name of a dummy parent with truncated net ID and driver prefix
 // getDummyName returns the name of a dummy parent with truncated net ID and driver prefix
 func getDummyName(netID string) string {
 func getDummyName(netID string) string {
-	return fmt.Sprintf("%s%s", dummyPrefix, netID)
+	return dummyPrefix + netID
 }
 }

+ 1 - 1
libnetwork/drivers/macvlan/macvlan_setup.go

@@ -205,5 +205,5 @@ func delDummyLink(linkName string) error {
 
 
 // getDummyName returns the name of a dummy parent with truncated net ID and driver prefix
 // getDummyName returns the name of a dummy parent with truncated net ID and driver prefix
 func getDummyName(netID string) string {
 func getDummyName(netID string) string {
-	return fmt.Sprintf("%s%s", dummyPrefix, netID)
+	return dummyPrefix + netID
 }
 }

+ 2 - 2
libnetwork/drivers/overlay/ov_network.go

@@ -430,7 +430,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
 	brIfaceOption := make([]osl.IfaceOption, 2)
 	brIfaceOption := make([]osl.IfaceOption, 2)
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP))
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP))
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true))
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true))
-	Ifaces[fmt.Sprintf("%s+%s", brName, "br")] = brIfaceOption
+	Ifaces[brName+"+br"] = brIfaceOption
 
 
 	err := sbox.Restore(Ifaces, nil, nil, nil)
 	err := sbox.Restore(Ifaces, nil, nil, nil)
 	if err != nil {
 	if err != nil {
@@ -440,7 +440,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
 	Ifaces = make(map[string][]osl.IfaceOption)
 	Ifaces = make(map[string][]osl.IfaceOption)
 	vxlanIfaceOption := make([]osl.IfaceOption, 1)
 	vxlanIfaceOption := make([]osl.IfaceOption, 1)
 	vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName))
 	vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName))
-	Ifaces[fmt.Sprintf("%s+%s", vxlanName, "vxlan")] = vxlanIfaceOption
+	Ifaces[vxlanName+"+vxlan"] = vxlanIfaceOption
 	err = sbox.Restore(Ifaces, nil, nil, nil)
 	err = sbox.Restore(Ifaces, nil, nil, nil)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 2 - 2
libnetwork/drivers/overlay/overlay.go

@@ -152,7 +152,7 @@ func (d *driver) restoreEndpoints() error {
 		Ifaces := make(map[string][]osl.IfaceOption)
 		Ifaces := make(map[string][]osl.IfaceOption)
 		vethIfaceOption := make([]osl.IfaceOption, 1)
 		vethIfaceOption := make([]osl.IfaceOption, 1)
 		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
 		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
-		Ifaces[fmt.Sprintf("%s+%s", "veth", "veth")] = vethIfaceOption
+		Ifaces["veth+veth"] = vethIfaceOption
 
 
 		err := n.sbox.Restore(Ifaces, nil, nil, nil)
 		err := n.sbox.Restore(Ifaces, nil, nil, nil)
 		if err != nil {
 		if err != nil {
@@ -251,7 +251,7 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
 		// If there is no cluster store there is no need to start serf.
 		// If there is no cluster store there is no need to start serf.
 		if d.store != nil {
 		if d.store != nil {
 			if err := validateSelf(advertiseAddress); err != nil {
 			if err := validateSelf(advertiseAddress); err != nil {
-				logrus.Warnf("%s", err.Error())
+				logrus.Warn(err.Error())
 			}
 			}
 			err := d.serfInit()
 			err := d.serfInit()
 			if err != nil {
 			if err != nil {

+ 2 - 2
libnetwork/drivers/solaris/overlay/ov_network.go

@@ -331,7 +331,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
 	brIfaceOption := make([]osl.IfaceOption, 2)
 	brIfaceOption := make([]osl.IfaceOption, 2)
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP))
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP))
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true))
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true))
-	Ifaces[fmt.Sprintf("%s+%s", brName, "br")] = brIfaceOption
+	Ifaces[brName+"+br"] = brIfaceOption
 
 
 	err := sbox.Restore(Ifaces, nil, nil, nil)
 	err := sbox.Restore(Ifaces, nil, nil, nil)
 	if err != nil {
 	if err != nil {
@@ -341,7 +341,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
 	Ifaces = make(map[string][]osl.IfaceOption)
 	Ifaces = make(map[string][]osl.IfaceOption)
 	vxlanIfaceOption := make([]osl.IfaceOption, 1)
 	vxlanIfaceOption := make([]osl.IfaceOption, 1)
 	vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName))
 	vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName))
-	Ifaces[fmt.Sprintf("%s+%s", vxlanName, "vxlan")] = vxlanIfaceOption
+	Ifaces[vxlanName+"+vxlan"] = vxlanIfaceOption
 	err = sbox.Restore(Ifaces, nil, nil, nil)
 	err = sbox.Restore(Ifaces, nil, nil, nil)
 	if err != nil {
 	if err != nil {
 		return err
 		return err

+ 2 - 2
libnetwork/drivers/solaris/overlay/overlay.go

@@ -140,7 +140,7 @@ func (d *driver) restoreEndpoints() error {
 		Ifaces := make(map[string][]osl.IfaceOption)
 		Ifaces := make(map[string][]osl.IfaceOption)
 		vethIfaceOption := make([]osl.IfaceOption, 1)
 		vethIfaceOption := make([]osl.IfaceOption, 1)
 		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
 		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
-		Ifaces[fmt.Sprintf("%s+%s", "veth", "veth")] = vethIfaceOption
+		Ifaces["veth+veth"] = vethIfaceOption
 
 
 		err := n.sbox.Restore(Ifaces, nil, nil, nil)
 		err := n.sbox.Restore(Ifaces, nil, nil, nil)
 		if err != nil {
 		if err != nil {
@@ -233,7 +233,7 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
 		// If there is no cluster store there is no need to start serf.
 		// If there is no cluster store there is no need to start serf.
 		if d.store != nil {
 		if d.store != nil {
 			if err := validateSelf(advertiseAddress); err != nil {
 			if err := validateSelf(advertiseAddress); err != nil {
-				logrus.Warnf("%s", err.Error())
+				logrus.Warn(err.Error())
 			}
 			}
 			err := d.serfInit()
 			err := d.serfInit()
 			if err != nil {
 			if err != nil {

+ 2 - 2
libnetwork/ipam/allocator.go

@@ -579,7 +579,7 @@ func (a *Allocator) DumpDatabase() string {
 		s = fmt.Sprintf("\n\n%s Config", as)
 		s = fmt.Sprintf("\n\n%s Config", as)
 		aSpace.Lock()
 		aSpace.Lock()
 		for k, config := range aSpace.subnets {
 		for k, config := range aSpace.subnets {
-			s = fmt.Sprintf("%s%s", s, fmt.Sprintf("\n%v: %v", k, config))
+			s += fmt.Sprintf("\n%v: %v", k, config)
 			if config.Range == nil {
 			if config.Range == nil {
 				a.retrieveBitmask(k, config.Pool)
 				a.retrieveBitmask(k, config.Pool)
 			}
 			}
@@ -589,7 +589,7 @@ func (a *Allocator) DumpDatabase() string {
 
 
 	s = fmt.Sprintf("%s\n\nBitmasks", s)
 	s = fmt.Sprintf("%s\n\nBitmasks", s)
 	for k, bm := range a.addresses {
 	for k, bm := range a.addresses {
-		s = fmt.Sprintf("%s%s", s, fmt.Sprintf("\n%s: %s", k, bm))
+		s += fmt.Sprintf("\n%s: %s", k, bm)
 	}
 	}
 
 
 	return s
 	return s

+ 2 - 2
libnetwork/types/types.go

@@ -129,11 +129,11 @@ func (p *PortBinding) GetCopy() PortBinding {
 func (p *PortBinding) String() string {
 func (p *PortBinding) String() string {
 	ret := fmt.Sprintf("%s/", p.Proto)
 	ret := fmt.Sprintf("%s/", p.Proto)
 	if p.IP != nil {
 	if p.IP != nil {
-		ret = fmt.Sprintf("%s%s", ret, p.IP.String())
+		ret += p.IP.String()
 	}
 	}
 	ret = fmt.Sprintf("%s:%d/", ret, p.Port)
 	ret = fmt.Sprintf("%s:%d/", ret, p.Port)
 	if p.HostIP != nil {
 	if p.HostIP != nil {
-		ret = fmt.Sprintf("%s%s", ret, p.HostIP.String())
+		ret += p.HostIP.String()
 	}
 	}
 	ret = fmt.Sprintf("%s:%d", ret, p.HostPort)
 	ret = fmt.Sprintf("%s:%d", ret, p.HostPort)
 	return ret
 	return ret