Browse code

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 authored on 2017/05/10 08:07:09
Showing 9 changed files
... ...
@@ -474,7 +474,7 @@ func verifyV4INCEntries(networks map[string]*bridgeNetwork, numEntries int, t *t
474 474
 			if x == y {
475 475
 				continue
476 476
 			}
477
-			re := regexp.MustCompile(fmt.Sprintf("%s %s", x.config.BridgeName, y.config.BridgeName))
477
+			re := regexp.MustCompile(x.config.BridgeName + " " + y.config.BridgeName)
478 478
 			matches := re.FindAllString(string(out[:]), -1)
479 479
 			if len(matches) != 1 {
480 480
 				t.Fatalf("Cannot find expected inter-network isolation rules in IP Tables:\n%s", string(out[:]))
... ...
@@ -201,5 +201,5 @@ func delDummyLink(linkName string) error {
201 201
 
202 202
 // getDummyName returns the name of a dummy parent with truncated net ID and driver prefix
203 203
 func getDummyName(netID string) string {
204
-	return fmt.Sprintf("%s%s", dummyPrefix, netID)
204
+	return dummyPrefix + netID
205 205
 }
... ...
@@ -205,5 +205,5 @@ func delDummyLink(linkName string) error {
205 205
 
206 206
 // getDummyName returns the name of a dummy parent with truncated net ID and driver prefix
207 207
 func getDummyName(netID string) string {
208
-	return fmt.Sprintf("%s%s", dummyPrefix, netID)
208
+	return dummyPrefix + netID
209 209
 }
... ...
@@ -430,7 +430,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
430 430
 	brIfaceOption := make([]osl.IfaceOption, 2)
431 431
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP))
432 432
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true))
433
-	Ifaces[fmt.Sprintf("%s+%s", brName, "br")] = brIfaceOption
433
+	Ifaces[brName+"+br"] = brIfaceOption
434 434
 
435 435
 	err := sbox.Restore(Ifaces, nil, nil, nil)
436 436
 	if err != nil {
... ...
@@ -440,7 +440,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
440 440
 	Ifaces = make(map[string][]osl.IfaceOption)
441 441
 	vxlanIfaceOption := make([]osl.IfaceOption, 1)
442 442
 	vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName))
443
-	Ifaces[fmt.Sprintf("%s+%s", vxlanName, "vxlan")] = vxlanIfaceOption
443
+	Ifaces[vxlanName+"+vxlan"] = vxlanIfaceOption
444 444
 	err = sbox.Restore(Ifaces, nil, nil, nil)
445 445
 	if err != nil {
446 446
 		return err
... ...
@@ -152,7 +152,7 @@ func (d *driver) restoreEndpoints() error {
152 152
 		Ifaces := make(map[string][]osl.IfaceOption)
153 153
 		vethIfaceOption := make([]osl.IfaceOption, 1)
154 154
 		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
155
-		Ifaces[fmt.Sprintf("%s+%s", "veth", "veth")] = vethIfaceOption
155
+		Ifaces["veth+veth"] = vethIfaceOption
156 156
 
157 157
 		err := n.sbox.Restore(Ifaces, nil, nil, nil)
158 158
 		if err != nil {
... ...
@@ -251,7 +251,7 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
251 251
 		// If there is no cluster store there is no need to start serf.
252 252
 		if d.store != nil {
253 253
 			if err := validateSelf(advertiseAddress); err != nil {
254
-				logrus.Warnf("%s", err.Error())
254
+				logrus.Warn(err.Error())
255 255
 			}
256 256
 			err := d.serfInit()
257 257
 			if err != nil {
... ...
@@ -331,7 +331,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
331 331
 	brIfaceOption := make([]osl.IfaceOption, 2)
332 332
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Address(s.gwIP))
333 333
 	brIfaceOption = append(brIfaceOption, sbox.InterfaceOptions().Bridge(true))
334
-	Ifaces[fmt.Sprintf("%s+%s", brName, "br")] = brIfaceOption
334
+	Ifaces[brName+"+br"] = brIfaceOption
335 335
 
336 336
 	err := sbox.Restore(Ifaces, nil, nil, nil)
337 337
 	if err != nil {
... ...
@@ -341,7 +341,7 @@ func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) erro
341 341
 	Ifaces = make(map[string][]osl.IfaceOption)
342 342
 	vxlanIfaceOption := make([]osl.IfaceOption, 1)
343 343
 	vxlanIfaceOption = append(vxlanIfaceOption, sbox.InterfaceOptions().Master(brName))
344
-	Ifaces[fmt.Sprintf("%s+%s", vxlanName, "vxlan")] = vxlanIfaceOption
344
+	Ifaces[vxlanName+"+vxlan"] = vxlanIfaceOption
345 345
 	err = sbox.Restore(Ifaces, nil, nil, nil)
346 346
 	if err != nil {
347 347
 		return err
... ...
@@ -140,7 +140,7 @@ func (d *driver) restoreEndpoints() error {
140 140
 		Ifaces := make(map[string][]osl.IfaceOption)
141 141
 		vethIfaceOption := make([]osl.IfaceOption, 1)
142 142
 		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
143
-		Ifaces[fmt.Sprintf("%s+%s", "veth", "veth")] = vethIfaceOption
143
+		Ifaces["veth+veth"] = vethIfaceOption
144 144
 
145 145
 		err := n.sbox.Restore(Ifaces, nil, nil, nil)
146 146
 		if err != nil {
... ...
@@ -233,7 +233,7 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
233 233
 		// If there is no cluster store there is no need to start serf.
234 234
 		if d.store != nil {
235 235
 			if err := validateSelf(advertiseAddress); err != nil {
236
-				logrus.Warnf("%s", err.Error())
236
+				logrus.Warn(err.Error())
237 237
 			}
238 238
 			err := d.serfInit()
239 239
 			if err != nil {
... ...
@@ -579,7 +579,7 @@ func (a *Allocator) DumpDatabase() string {
579 579
 		s = fmt.Sprintf("\n\n%s Config", as)
580 580
 		aSpace.Lock()
581 581
 		for k, config := range aSpace.subnets {
582
-			s = fmt.Sprintf("%s%s", s, fmt.Sprintf("\n%v: %v", k, config))
582
+			s += fmt.Sprintf("\n%v: %v", k, config)
583 583
 			if config.Range == nil {
584 584
 				a.retrieveBitmask(k, config.Pool)
585 585
 			}
... ...
@@ -589,7 +589,7 @@ func (a *Allocator) DumpDatabase() string {
589 589
 
590 590
 	s = fmt.Sprintf("%s\n\nBitmasks", s)
591 591
 	for k, bm := range a.addresses {
592
-		s = fmt.Sprintf("%s%s", s, fmt.Sprintf("\n%s: %s", k, bm))
592
+		s += fmt.Sprintf("\n%s: %s", k, bm)
593 593
 	}
594 594
 
595 595
 	return s
... ...
@@ -129,11 +129,11 @@ func (p *PortBinding) GetCopy() PortBinding {
129 129
 func (p *PortBinding) String() string {
130 130
 	ret := fmt.Sprintf("%s/", p.Proto)
131 131
 	if p.IP != nil {
132
-		ret = fmt.Sprintf("%s%s", ret, p.IP.String())
132
+		ret += p.IP.String()
133 133
 	}
134 134
 	ret = fmt.Sprintf("%s:%d/", ret, p.Port)
135 135
 	if p.HostIP != nil {
136
-		ret = fmt.Sprintf("%s%s", ret, p.HostIP.String())
136
+		ret += p.HostIP.String()
137 137
 	}
138 138
 	ret = fmt.Sprintf("%s:%d", ret, p.HostPort)
139 139
 	return ret