Skip to content

Conversation

@jfantinhardesty
Copy link
Contributor

Type of Change

  • Bug fix
  • New feature
  • Code quality improvement
  • Other (describe):

Description

This PR improves some of the go code using more modern go code, such as using the slices package when working with slices and using the range keyword. These fixes were automatically applied using the go modernize tool provided by the go team. You can run this tool using

go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix ./...

  • Feature / Bug Fix: (Brief description of the feature or issue being addressed)

How Has This Been Tested?

Ran unit tests locally.

Checklist

  • The purpose of this PR is explained in this or a referenced issue.
  • Tests are included and/or updated for code changes.
  • Documentation update required.
  • Updates to module CHANGELOG.md are included.
  • License headers are included in each file.

Related Links

Copilot AI review requested due to automatic review settings June 4, 2025 21:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modernizes the Go code by replacing the generic interface{} with the new any type and updating loop constructs using the range keyword and new helper functions (such as strings.SplitSeq). However, some of the automated for‑loop modifications now iterate over integers instead of iterables, which may introduce compilation errors.

  • Updated method signatures by replacing interface{} with any.
  • Replaced traditional for‑loop constructs with range expressions.
  • Introduced new functions like strings.SplitSeq and slices package methods.

Reviewed Changes

Copilot reviewed 52 out of 52 changed files in this pull request and generated no comments.

Show a summary per file
File Description
component/azstorage/*.go Updated getServiceClient return types to any.
common/version.go Modified for‑loop iteration over a numeric literal.
common/util.go Changed for‑loops for iterating over strings.Split and pids.
common/log/* Updated logging function signatures to use any.
common/config/*.go Updated merge and iteration loops to use any and range over int.
common/cache_policy/lru_policy.go Modified for‑loop iteration over cache.List.Len() with range.
cmd/root.go Updated for‑loops over string slices from strings.SplitSeq.
cmd/mount.go Modified for‑loop iteration over a numeric literal using range.
Comments suppressed due to low confidence (10)

cmd/root.go:81

  • This change causes the loop to iterate over indices rather than string values from processes; restore the original 'for _, process := range processes' to correctly access the process strings.
for process := range processes {

cmd/mount.go:468

  • Using 'for l := range 3' to iterate three times is invalid in Go since an integer is not an iterable; revert to a conventional loop to achieve the intended iteration.
for l := range 3 {

common/version.go:99

  • Using 'for i := range 3' is not valid in Go, because 'range' requires an iterable (such as a slice, array, or map) rather than an integer literal.
for i := range 3 {

common/util.go:75

  • Iterating with 'for line := range ...' over the result of strings.SplitSeq returns indices, not the actual string elements, which will break subsequent string processing.
for line := range strings.SplitSeq(string(mntList), "\n") {

common/util.go:110

  • Using 'for pid := range pids' will iterate over the indices of the slice returned by strings.SplitSeq rather than the string values, likely causing logic errors.
for pid := range pids {

common/log/logger_test.go:51

  • Attempting to iterate over an integer using range is not allowed in Go. A traditional loop (e.g. 'for i := 0; i < count; i++') should be used instead.
for i := range lts.log_rotate_test_count {

common/config/keys_tree.go:234

  • Using 'range' on an integer (the result of elem.NumField()) is invalid; revert to the conventional for-loop format to iterate over struct fields.
for i := range elem.NumField() {

common/config/keys_tree.go:271

  • Iterating over the number of fields with a range loop on an integer is incorrect. The classic for-loop (using an index variable starting from 0 up to elem.NumField()) is required here.
for i := range elem.NumField() {

common/cache_policy/lru_policy.go:171

  • Using 'range' on the integer returned by cache.List.Len() is not valid; replace it with a traditional loop to iterate over the list length.
for range cache.List.Len() {

cmd/root.go:249

  • Replacing the traditional iteration over opts with 'for o := range opts' will yield indices instead of the option values; use 'for _, o := range opts' to iterate over the actual elements.
for o := range opts {

@vibhansa-msft vibhansa-msft added this to the v2-2.6.0 milestone Jun 30, 2025
@vibhansa-msft vibhansa-msft modified the milestones: v2-2.6.0, v2-2.5.1 Jul 29, 2025
@syeleti-msft
Copy link
Member

syeleti-msft commented Aug 1, 2025

Thanks for your Contribution!

@syeleti-msft syeleti-msft merged commit d77bc8c into Azure:main Aug 1, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants