Skip to content

refactor: use any instead of interface{}#21

Merged
eynopv merged 1 commit intomasterfrom
refactor/use-any
Apr 6, 2025
Merged

refactor: use any instead of interface{}#21
eynopv merged 1 commit intomasterfrom
refactor/use-any

Conversation

@eynopv
Copy link
Owner

@eynopv eynopv commented Apr 6, 2025

Summary by CodeRabbit

  • Refactor
    • Updated internal type declarations to a modern, more flexible alias, ensuring improved consistency and maintainability.
  • Tests
    • Adjusted test cases to align with the updated type definitions, ensuring consistent behavior across the system.

@coderabbitai
Copy link

coderabbitai bot commented Apr 6, 2025

Walkthrough

The pull request updates various Go source files by replacing the use of interface{} and map[string]interface{} with the more concise aliases any and map[string]any. These changes are applied in command handling, parameter resolution, YAML unmarshalling, template interpolation, file loading, and map flattening functions, as well as in their corresponding tests. The modifications are purely syntactical and do not modify the underlying functionality or control flow of the application.

Changes

File(s) Change Summary
cmd/root.go, cmd/run.go Updated map types from map[string]interface{} to map[string]any in the variable declarations and function signatures for command-related operations.
pkg/param/param.go, pkg/param/param_test.go Changed type for the replacements parameter in the Resolve method and in tests from map[string]interface{} to map[string]any.
pkg/request/request.go, pkg/request/template.go, pkg/request/template_test.go Modified the YAML unmarshalling functions and template interpolation to use any and map[string]any instead of interface{} and map[string]interface{}.
pkg/utils/file_utils.go, pkg/utils/map_utils.go, pkg/utils/map_utils_test.go Revised function signatures and variable declarations by replacing interface{} with any and updating maps to map[string]any, including the use of maps.Copy in the map flattening utility.

Possibly related PRs


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 186ecd2 and aebb14d.

📒 Files selected for processing (10)
  • cmd/root.go (1 hunks)
  • cmd/run.go (2 hunks)
  • pkg/param/param.go (1 hunks)
  • pkg/param/param_test.go (5 hunks)
  • pkg/request/request.go (2 hunks)
  • pkg/request/template.go (1 hunks)
  • pkg/request/template_test.go (1 hunks)
  • pkg/utils/file_utils.go (1 hunks)
  • pkg/utils/map_utils.go (2 hunks)
  • pkg/utils/map_utils_test.go (1 hunks)
🔇 Additional comments (17)
pkg/utils/file_utils.go (1)

13-13: Modern Go type usage with any instead of interface{}

This change updates the function signature to use the more concise any type introduced in Go 1.18 as an alias for interface{}. This improves code readability while maintaining identical functionality.

cmd/root.go (1)

52-52: Modern Go type usage with any instead of interface{}

Updating the type of the Variables map from map[string]interface{} to map[string]any aligns with modern Go practices and improves code readability. This is a syntactic change that maintains identical functionality.

pkg/request/template.go (1)

31-31: Modern Go type usage with any instead of interface{}

This change updates the method signature to use the more concise any type instead of interface{} for the vars parameter. This is consistent with the changes made in other files and follows modern Go conventions.

pkg/utils/map_utils_test.go (1)

10-13: Modern Go type usage with any instead of interface{}

This test has been updated to use map[string]any instead of map[string]interface{} for both the outer map and nested maps, which aligns with modern Go practices and is consistent with changes made in other files.

pkg/request/template_test.go (1)

110-110: Good use of any instead of interface{}

This change correctly replaces map[string]interface{} with map[string]any, which is more concise while maintaining the same functionality. The any type was introduced in Go 1.18 as an alias for interface{}.

pkg/param/param.go (1)

11-11: Good update to method signature using any

The Resolve method's signature has been updated to use map[string]any instead of map[string]interface{}, which makes the code more concise while maintaining the same functionality.

pkg/utils/map_utils.go (3)

8-8: Good update to function signature using any

The FlattenMap function's signature has been updated to use map[string]any instead of map[string]interface{}, which is more concise while maintaining the same functionality.


20-20: Good update to case statement using any

The switch case has been updated to use map[string]any instead of map[string]interface{}, which is consistent with the function signature change.


22-22: Improved map merging with maps.Copy

The change from manually copying values in a loop to using maps.Copy() improves code readability and likely performance. This is a good enhancement alongside the type updates.

pkg/request/request.go (2)

36-36: Good use of any instead of interface{}

The variable type has been updated from interface{} to any, which is a more concise alias introduced in Go 1.18.


70-70: Good use of any instead of interface{}

The variable type has been updated from interface{} to any, which is a more concise alias introduced in Go 1.18.

cmd/run.go (3)

17-17: Great modernization of type syntax!

Using the any type alias instead of interface{} improves code readability while maintaining the same functionality. This follows the modern Go conventions introduced in Go 1.18.


46-46: Good consistent use of the any type alias!

The change from map[string]interface{} to map[string]any is consistent with the previous parameter change and follows modern Go conventions.


15-50:

Details

✅ Verification successful

Verify minimum Go version requirement

Since the any type alias was introduced in Go 1.18, please ensure that the project's minimum Go version requirement is at least 1.18.


🏁 Script executed:

#!/bin/bash
# Check go.mod file for minimum Go version
if [ -f go.mod ]; then
  echo "Checking go.mod for minimum Go version:"
  grep -E "^go [0-9]+\.[0-9]+" go.mod
else
  echo "go.mod file not found. Checking for other Go version indicators."
  # Look for any CI configuration files that might specify Go version
  for file in .github/workflows/*.yml .travis.yml .circleci/config.yml; do
    if [ -f "$file" ]; then
      echo "Found CI configuration file: $file"
      echo "Go version references:"
      grep -E "go[0-9]+\.[0-9]+" "$file" || echo "No explicit Go version found in $file"
    fi
  done
fi

Length of output: 156


Minimal Go Version Requirement Verified

The project's go.mod file correctly specifies go 1.24.0, which exceeds the minimum requirement of Go 1.18. No changes are needed for the usage of the any type.

pkg/param/param_test.go (3)

58-58: Good use of modern Go syntax!

Replacing map[string]interface{} with the more concise map[string]any type alias improves code readability.


71-71: Consistent application of the any type alias!

The consistent replacement of map[string]interface{} with map[string]any across all test cases maintains code uniformity and follows modern Go conventions.

Also applies to: 84-84, 95-95, 106-106


1-126:

Details

✅ Verification successful

Ensure test compatibility with updated function signatures

These test changes look good, but they assume that the Resolve method in the param package has also been updated to accept map[string]any instead of map[string]interface{}.


🏁 Script executed:

#!/bin/bash
# Verify that the Resolve function signature in param.go matches the test usage
if [ -f pkg/param/param.go ]; then
  echo "Checking Resolve method signature in param.go:"
  grep -A 3 "func.*Resolve" pkg/param/param.go
else
  echo "param.go file not found at expected location."
  # Try to find it elsewhere
  fd -t f "param.go" | xargs grep -l "func.*Resolve"
fi

Length of output: 392


Verified Function Signature Update in pkg/param/param.go

The test changes are consistent with the updated function signature. The Resolve method now accepts a map[string]any as expected, which matches the tests' assumptions.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@eynopv eynopv merged commit 1a9bc46 into master Apr 6, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant