Merge pull request #14753 from sashamelentyev/replaceall

all: Use ReplaceAll instead of Replace with -1 pos
This commit is contained in:
Benjamin Wang 2022-11-15 05:43:10 +08:00 committed by GitHub
commit efa144a66a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 12 additions and 12 deletions

View File

@ -96,8 +96,8 @@ func handler(w http.ResponseWriter, r *http.Request) {
} }
func escape(s string) string { func escape(s string) string {
escaped := strings.Replace(s, "\n", " ", -1) escaped := strings.ReplaceAll(s, "\n", " ")
escaped = strings.Replace(escaped, "\r", " ", -1) escaped = strings.ReplaceAll(escaped, "\r", " ")
return escaped return escaped
} }

View File

@ -99,7 +99,7 @@ GLOBAL OPTIONS:
{{end}} {{end}}
`[1:] `[1:]
commandUsageTemplate = template.Must(template.New("command_usage").Funcs(templFuncs).Parse(strings.Replace(commandUsage, "\\\n", "", -1))) commandUsageTemplate = template.Must(template.New("command_usage").Funcs(templFuncs).Parse(strings.ReplaceAll(commandUsage, "\\\n", "")))
} }
func etcdFlagUsages(flagSet *pflag.FlagSet) string { func etcdFlagUsages(flagSet *pflag.FlagSet) string {

View File

@ -66,7 +66,7 @@ func SetPflagsFromEnv(lg *zap.Logger, prefix string, fs *pflag.FlagSet) error {
// FlagToEnv converts flag string to upper-case environment variable key string. // FlagToEnv converts flag string to upper-case environment variable key string.
func FlagToEnv(prefix, name string) string { func FlagToEnv(prefix, name string) string {
return prefix + "_" + strings.ToUpper(strings.Replace(name, "-", "_", -1)) return prefix + "_" + strings.ToUpper(strings.ReplaceAll(name, "-", "_"))
} }
func verifyEnv(lg *zap.Logger, prefix string, usedEnvKey, alreadySet map[string]bool) { func verifyEnv(lg *zap.Logger, prefix string, usedEnvKey, alreadySet map[string]bool) {

View File

@ -106,7 +106,7 @@ func TestAuthority(t *testing.T) {
} }
testutils.ExecuteWithTimeout(t, 5*time.Second, func() { testutils.ExecuteWithTimeout(t, 5*time.Second, func() {
assertAuthority(t, strings.Replace(tc.expectAuthorityPattern, "${MEMBER_PORT}", "20000", -1), epc) assertAuthority(t, strings.ReplaceAll(tc.expectAuthorityPattern, "${MEMBER_PORT}", "20000"), epc)
}) })
}) })
@ -119,7 +119,7 @@ func templateEndpoints(t *testing.T, pattern string, clus *e2e.EtcdProcessCluste
var endpoints []string var endpoints []string
for i := 0; i < clus.Cfg.ClusterSize; i++ { for i := 0; i < clus.Cfg.ClusterSize; i++ {
ent := pattern ent := pattern
ent = strings.Replace(ent, "${MEMBER_PORT}", fmt.Sprintf("%d", e2e.EtcdProcessBasePort+i*5), -1) ent = strings.ReplaceAll(ent, "${MEMBER_PORT}", fmt.Sprintf("%d", e2e.EtcdProcessBasePort+i*5))
endpoints = append(endpoints, ent) endpoints = append(endpoints, ent)
} }
return endpoints return endpoints

View File

@ -101,7 +101,7 @@ GLOBAL OPTIONS:
{{end}} {{end}}
`[1:] `[1:]
commandUsageTemplate = template.Must(template.New("command_usage").Funcs(templFuncs).Parse(strings.Replace(commandUsage, "\\\n", "", -1))) commandUsageTemplate = template.Must(template.New("command_usage").Funcs(templFuncs).Parse(strings.ReplaceAll(commandUsage, "\\\n", "")))
} }
func etcdFlagUsages(flagSet *pflag.FlagSet) string { func etcdFlagUsages(flagSet *pflag.FlagSet) string {

View File

@ -146,8 +146,8 @@ func templateEndpoints(t *testing.T, pattern string, clus *integration.Cluster)
var endpoints []string var endpoints []string
for _, m := range clus.Members { for _, m := range clus.Members {
ent := pattern ent := pattern
ent = strings.Replace(ent, "${MEMBER_PORT}", m.GrpcPortNumber(), -1) ent = strings.ReplaceAll(ent, "${MEMBER_PORT}", m.GrpcPortNumber())
ent = strings.Replace(ent, "${MEMBER_NAME}", m.Name, -1) ent = strings.ReplaceAll(ent, "${MEMBER_NAME}", m.Name)
endpoints = append(endpoints, ent) endpoints = append(endpoints, ent)
} }
return endpoints return endpoints
@ -156,8 +156,8 @@ func templateEndpoints(t *testing.T, pattern string, clus *integration.Cluster)
func templateAuthority(t *testing.T, pattern string, m *integration.Member) string { func templateAuthority(t *testing.T, pattern string, m *integration.Member) string {
t.Helper() t.Helper()
authority := pattern authority := pattern
authority = strings.Replace(authority, "${MEMBER_PORT}", m.GrpcPortNumber(), -1) authority = strings.ReplaceAll(authority, "${MEMBER_PORT}", m.GrpcPortNumber())
authority = strings.Replace(authority, "${MEMBER_NAME}", m.Name, -1) authority = strings.ReplaceAll(authority, "${MEMBER_NAME}", m.Name)
return authority return authority
} }

View File

@ -219,7 +219,7 @@ func persistMemberDataDir(t *testing.T, clus *e2e.EtcdProcessCluster, path strin
} }
func testResultsDirectory(t *testing.T) (string, error) { func testResultsDirectory(t *testing.T) (string, error) {
path, err := filepath.Abs(filepath.Join(resultsDirectory, strings.Replace(t.Name(), "/", "_", -1))) path, err := filepath.Abs(filepath.Join(resultsDirectory, strings.ReplaceAll(t.Name(), "/", "_")))
if err != nil { if err != nil {
return path, err return path, err
} }