mirror of https://github.com/grpc/grpc-go.git
.*: Use `strings.ReplaceAll(.....)` (#7554)
This commit is contained in:
parent
6d976887d4
commit
a8e6e11cf0
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue