Skip to content

Commit cf5a571

Browse files
authored
Merge pull request #20978 from boqishan/main
refactor: use strings.Cut to simplify code
2 parents 584c7cc + 69b49d1 commit cf5a571

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

tools/benchmark/cmd/util.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,16 @@ func getUsernamePassword(usernameFlag string) (string, string, error) {
3737
if globalUserName != "" && globalPassword != "" {
3838
return globalUserName, globalPassword, nil
3939
}
40-
colon := strings.Index(usernameFlag, ":")
41-
if colon == -1 {
40+
var ok bool
41+
globalUserName, globalPassword, ok = strings.Cut(usernameFlag, ":")
42+
if !ok {
4243
// Prompt for the password.
4344
password, err := speakeasy.Ask("Password: ")
4445
if err != nil {
4546
return "", "", err
4647
}
4748
globalUserName = usernameFlag
4849
globalPassword = password
49-
} else {
50-
globalUserName = usernameFlag[:colon]
51-
globalPassword = usernameFlag[colon+1:]
5250
}
5351
return globalUserName, globalPassword, nil
5452
}

0 commit comments

Comments
 (0)