refactor: replace strings.Replace with strings.ReplaceAll (#15392)

strings.ReplaceAll(s, old, new) is a wrapper function for
strings.Replace(s, old, new, -1). But strings.ReplaceAll is more
readable and removes the hardcoded -1.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-08-04 03:22:48 +08:00
committed by GitHub
parent 475a88e813
commit 6141d61839
36 changed files with 56 additions and 56 deletions

View File

@@ -106,7 +106,7 @@ func (h *HANA) NewUser(ctx context.Context, req dbplugin.NewUserRequest) (respon
}
// HANA does not allow hyphens in usernames, and highly prefers capital letters
username = strings.Replace(username, "-", "_", -1)
username = strings.ReplaceAll(username, "-", "_")
username = strings.ToUpper(username)
// If expiration is in the role SQL, HANA will deactivate the user when time is up,

View File

@@ -16,7 +16,7 @@ import (
const (
defaultMysqlRevocationStmts = `
REVOKE ALL PRIVILEGES, GRANT OPTION FROM '{{name}}'@'%';
REVOKE ALL PRIVILEGES, GRANT OPTION FROM '{{name}}'@'%';
DROP USER '{{name}}'@'%'
`
@@ -174,8 +174,8 @@ func (m *MySQL) DeleteUser(ctx context.Context, req dbplugin.DeleteUserRequest)
// This is not a prepared statement because not all commands are supported
// 1295: This command is not supported in the prepared statement protocol yet
// Reference https://mariadb.com/kb/en/mariadb/prepare-statement/
query = strings.Replace(query, "{{name}}", req.Username, -1)
query = strings.Replace(query, "{{username}}", req.Username, -1)
query = strings.ReplaceAll(query, "{{name}}", req.Username)
query = strings.ReplaceAll(query, "{{username}}", req.Username)
_, err = tx.ExecContext(ctx, query)
if err != nil {
return dbplugin.DeleteUserResponse{}, err

View File

@@ -482,7 +482,7 @@ func containsMultilineStatement(stmt string) bool {
}
stmtWithoutLiterals := stmt
for _, literal := range literals {
stmtWithoutLiterals = strings.Replace(stmt, literal, "", -1)
stmtWithoutLiterals = strings.ReplaceAll(stmt, literal, "")
}
// Now look for the word "END" specifically. This will miss any
// representations of END that aren't surrounded by spaces, but