Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.*: Use strings.ReplaceAll(.....) #7554

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/googlecloud/googlecloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/xds/bootstrap/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 5 additions & 5 deletions resolver_balancer_ext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down Expand Up @@ -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})

Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion stats/opencensus/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions stats/opencensus/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.".
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions xds/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
Loading