diff --git a/util/argo/diff/diff.go b/util/argo/diff/diff.go index 6ee4f6c4af..e9e3721586 100644 --- a/util/argo/diff/diff.go +++ b/util/argo/diff/diff.go @@ -353,7 +353,7 @@ func diffArrayCached(configArray []*unstructured.Unstructured, liveArray []*unst Diffs: make([]diff.DiffResult, numItems), } - for i := 0; i < numItems; i++ { + for i := range numItems { config := configArray[i] live := liveArray[i] resourceVersion := "" diff --git a/util/cli/cli.go b/util/cli/cli.go index 0d44bf3233..4447d9699e 100644 --- a/util/cli/cli.go +++ b/util/cli/cli.go @@ -247,7 +247,7 @@ const ( func setComments(input []byte, comments string) []byte { input = stripComments(input) var commentLines []string - for _, line := range strings.Split(comments, "\n") { + for line := range strings.SplitSeq(comments, "\n") { if line != "" { commentLines = append(commentLines, "# "+line) } diff --git a/util/env/env.go b/util/env/env.go index 47da9175d5..e88c9303d8 100644 --- a/util/env/env.go +++ b/util/env/env.go @@ -202,7 +202,7 @@ func ParseStringToStringFromEnv(envVar string, defaultValue map[string]string, s } parsed := make(map[string]string) - for _, pair := range strings.Split(str, separator) { + for pair := range strings.SplitSeq(str, separator) { keyvalue := strings.Split(pair, "=") if len(keyvalue) != 2 { log.Warnf("Invalid key-value pair when parsing environment '%s' as a string map", str) diff --git a/util/lua/lua.go b/util/lua/lua.go index ddc1aff788..cde07ef89d 100644 --- a/util/lua/lua.go +++ b/util/lua/lua.go @@ -144,7 +144,7 @@ func (vm VM) ExecuteHealthLua(obj *unstructured.Unstructured, script string) (*h err = json.Unmarshal(jsonBytes, healthStatus) if err != nil { // Validate if the error is caused by an empty object - typeError := &json.UnmarshalTypeError{Value: "array", Type: reflect.TypeOf(healthStatus)} + typeError := &json.UnmarshalTypeError{Value: "array", Type: reflect.TypeFor[*health.HealthStatus]()} if errors.As(err, &typeError) { return &health.HealthStatus{}, nil } diff --git a/util/password/password.go b/util/password/password.go index 41f34f079e..36789f3560 100644 --- a/util/password/password.go +++ b/util/password/password.go @@ -85,10 +85,7 @@ func (h DummyPasswordHasher) VerifyPassword(password, hashedPassword string) boo // HashPassword creates a one-way digest ("hash") of a password. In the case of Bcrypt, a pseudorandom salt is included automatically by the underlying library. For security reasons, the work factor is always at _least_ bcrypt.DefaultCost. func (h BcryptPasswordHasher) HashPassword(password string) (string, error) { - cost := h.Cost - if cost < bcrypt.DefaultCost { - cost = bcrypt.DefaultCost - } + cost := max(h.Cost, bcrypt.DefaultCost) hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), cost) if err != nil { hashedPassword = []byte("") diff --git a/util/rand/rand.go b/util/rand/rand.go index 82603da176..9b2853c053 100644 --- a/util/rand/rand.go +++ b/util/rand/rand.go @@ -18,7 +18,7 @@ func String(n int) (string, error) { func StringFromCharset(n int, charset string) (string, error) { b := make([]byte, n) maxIdx := big.NewInt(int64(len(charset))) - for i := 0; i < n; i++ { + for i := range n { randIdx, err := rand.Int(rand.Reader, maxIdx) if err != nil { return "", fmt.Errorf("failed to generate random string: %w", err) diff --git a/util/webhook/webhook_test.go b/util/webhook/webhook_test.go index d2efa56610..747e586efa 100644 --- a/util/webhook/webhook_test.go +++ b/util/webhook/webhook_test.go @@ -523,7 +523,7 @@ func Test_affectedRevisionInfo_appRevisionHasChanged(t *testing.T) { // The payload's "push.changes[0].new.name" member seems to only have the branch name (based on the example payload). // https://support.atlassian.com/bitbucket-cloud/docs/event-payloads/#EventPayloads-Push var pl bitbucket.RepoPushPayload - err := json.Unmarshal([]byte(fmt.Sprintf(`{"push":{"changes":[{"new":{"name":%q}}]}}`, branchName)), &pl) + err := json.Unmarshal(fmt.Appendf(nil, `{"push":{"changes":[{"new":{"name":%q}}]}}`, branchName), &pl) require.NoError(t, err) return pl }