diff --git a/internal/googlecloud/googlecloud.go b/internal/googlecloud/googlecloud.go index 6717b757f80d..43423d8ad9ab 100644 --- a/internal/googlecloud/googlecloud.go +++ b/internal/googlecloud/googlecloud.go @@ -62,9 +62,9 @@ func isRunningOnGCE(manufacturer []byte, goos string) bool { name = strings.TrimSpace(name) return name == "Google" || name == "Google Compute Engine" case "windows": - name = strings.Replace(name, " ", "", -1) - name = strings.Replace(name, "\n", "", -1) - name = strings.Replace(name, "\r", "", -1) + name = strings.ReplaceAll(name, " ", "") + name = strings.ReplaceAll(name, "\n", "") + name = strings.ReplaceAll(name, "\r", "") return name == "Google" default: return false diff --git a/internal/xds/bootstrap/template.go b/internal/xds/bootstrap/template.go index 9b51fcc83972..ec1a30919ec9 100644 --- a/internal/xds/bootstrap/template.go +++ b/internal/xds/bootstrap/template.go @@ -34,7 +34,7 @@ func PopulateResourceTemplate(template, target string) string { if strings.HasPrefix(template, "xdstp:") { target = percentEncode(target) } - return strings.Replace(template, "%s", target, -1) + return strings.ReplaceAll(template, "%s", target) } // percentEncode percent encode t, except for "/". See the tests for examples. diff --git a/resolver_balancer_ext_test.go b/resolver_balancer_ext_test.go index a2e35ccf3822..417a5781ef80 100644 --- a/resolver_balancer_ext_test.go +++ b/resolver_balancer_ext_test.go @@ -45,7 +45,7 @@ import ( // 4. balancer.ClientConn.ResolveNow() -> // 5. resolver.Resolver.ResolveNow() -> func (s) TestResolverBalancerInteraction(t *testing.T) { - name := strings.Replace(strings.ToLower(t.Name()), "/", "", -1) + name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "") bf := stub.BalancerFuncs{ UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { bd.ClientConn.ResolveNow(resolver.ResolveNowOptions{}) @@ -104,7 +104,7 @@ func (b *resolverBuilderWithErr) Close() {} // 4. resolver.Builder.Build() fails. func (s) TestResolverBuildFailure(t *testing.T) { enterIdle := internal.EnterIdleModeForTesting.(func(*grpc.ClientConn)) - name := strings.Replace(strings.ToLower(t.Name()), "/", "", -1) + name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "") resErrCh := make(chan error, 1) resolver.Register(&resolverBuilderWithErr{errCh: resErrCh, scheme: name}) @@ -130,7 +130,7 @@ func (s) TestResolverBuildFailure(t *testing.T) { // the channel enters idle mode. func (s) TestEnterIdleDuringResolverUpdateState(t *testing.T) { enterIdle := internal.EnterIdleModeForTesting.(func(*grpc.ClientConn)) - name := strings.Replace(strings.ToLower(t.Name()), "/", "", -1) + name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "") // Create a manual resolver that spams UpdateState calls until it is closed. rb := manual.NewBuilderWithScheme(name) @@ -175,7 +175,7 @@ func (s) TestEnterIdleDuringResolverUpdateState(t *testing.T) { // time as the balancer being closed while the channel enters idle mode. func (s) TestEnterIdleDuringBalancerUpdateState(t *testing.T) { enterIdle := internal.EnterIdleModeForTesting.(func(*grpc.ClientConn)) - name := strings.Replace(strings.ToLower(t.Name()), "/", "", -1) + name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "") // Create a balancer that calls UpdateState once asynchronously, attempting // to make the channel appear ready even after entering idle. @@ -220,7 +220,7 @@ func (s) TestEnterIdleDuringBalancerNewSubConn(t *testing.T) { channelz.TurnOn() defer internal.ChannelzTurnOffForTesting() enterIdle := internal.EnterIdleModeForTesting.(func(*grpc.ClientConn)) - name := strings.Replace(strings.ToLower(t.Name()), "/", "", -1) + name := strings.ReplaceAll(strings.ToLower(t.Name()), "/", "") // Create a balancer that calls NewSubConn once asynchronously, attempting // to create a subchannel after going idle. diff --git a/stats/opencensus/opencensus.go b/stats/opencensus/opencensus.go index f477d0918a37..ff13537f15f4 100644 --- a/stats/opencensus/opencensus.go +++ b/stats/opencensus/opencensus.go @@ -88,7 +88,7 @@ func ServerOption(to TraceOptions) grpc.ServerOption { func (csh *clientStatsHandler) createCallSpan(ctx context.Context, method string) (context.Context, *trace.Span) { var span *trace.Span if !csh.to.DisableTrace { - mn := strings.Replace(removeLeadingSlash(method), "/", ".", -1) + mn := strings.ReplaceAll(removeLeadingSlash(method), "/", ".") ctx, span = trace.StartSpan(ctx, mn, trace.WithSampler(csh.to.TS), trace.WithSpanKind(trace.SpanKindClient)) } return ctx, span diff --git a/stats/opencensus/trace.go b/stats/opencensus/trace.go index 5a5438e1cc39..41a5bef27e5f 100644 --- a/stats/opencensus/trace.go +++ b/stats/opencensus/trace.go @@ -39,7 +39,7 @@ type traceInfo struct { // about this span into gRPC Metadata. func (csh *clientStatsHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) (context.Context, *traceInfo) { // TODO: get consensus on whether this method name of "s.m" is correct. - mn := "Attempt." + strings.Replace(removeLeadingSlash(rti.FullMethodName), "/", ".", -1) + mn := "Attempt." + strings.ReplaceAll(removeLeadingSlash(rti.FullMethodName), "/", ".") // Returned context is ignored because will populate context with data that // wraps the span instead. Don't set span kind client on this attempt span // to prevent backend from prepending span name with "Sent.". @@ -57,7 +57,7 @@ func (csh *clientStatsHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTa // spanContext deserialized from context passed in (wire data in gRPC metadata) // if present. func (ssh *serverStatsHandler) traceTagRPC(ctx context.Context, rti *stats.RPCTagInfo) (context.Context, *traceInfo) { - mn := strings.Replace(removeLeadingSlash(rti.FullMethodName), "/", ".", -1) + mn := strings.ReplaceAll(removeLeadingSlash(rti.FullMethodName), "/", ".") var span *trace.Span if sc, ok := propagation.FromBinary(stats.Trace(ctx)); ok { diff --git a/xds/server_test.go b/xds/server_test.go index 9a56fc754d78..87ddf9c78e7e 100644 --- a/xds/server_test.go +++ b/xds/server_test.go @@ -410,7 +410,7 @@ func (s) TestServeSuccess(t *testing.T) { case <-ctx.Done(): t.Fatalf("Timeout when waiting for an LDS request to be sent out") } - wantNames := []string{strings.Replace(e2e.ServerListenerResourceNameTemplate, "%s", lis.Addr().String(), -1)} + wantNames := []string{strings.ReplaceAll(e2e.ServerListenerResourceNameTemplate, "%s", lis.Addr().String())} if !cmp.Equal(gotNames, wantNames) { t.Fatalf("LDS watch registered for names %v, want %v", gotNames, wantNames) } @@ -647,7 +647,7 @@ func (s) TestHandleListenerUpdate_ErrorUpdate(t *testing.T) { case <-ctx.Done(): t.Fatalf("Timeout when waiting for an LDS request to be sent out") } - wantNames := []string{strings.Replace(e2e.ServerListenerResourceNameTemplate, "%s", lis.Addr().String(), -1)} + wantNames := []string{strings.ReplaceAll(e2e.ServerListenerResourceNameTemplate, "%s", lis.Addr().String())} if !cmp.Equal(gotNames, wantNames) { t.Fatalf("LDS watch registered for names %v, want %v", gotNames, wantNames) }