docs: fix route group example code #4020
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have identified a couple of issues with the current example code for route groups in the documentation. Below are the details of these issues and the proposed fix.
Issues
In the current example code, there is a risk of making a typo that can lead to unintended behavior:
In the code above, the intention is to add endpoints to the v2 group, but due to a typo, the endpoint might accidentally be added to the v1 group instead. This issue is problematic because the code will compile and run without errors, potentially leading to confusion for beginners.
Proposed Fix
By making the following changes, we can ensure that route groups are clearly separated and reduce the risk of accidentally adding endpoints to the wrong group:
This change will clearly separate the endpoints for each version, helping to prevent the mistake of adding endpoints to the wrong version.
I believe that incorporating this fix into the documentation will help users who are new to Gin avoid this issue. If this pull request is accepted, I also plan to submit a similar update to the gin-gonic/website repository.
Thank you for considering this request.
This version provides a clear explanation of the problem and the proposed solution, making it easy for reviewers to understand the importance of the change and its impact.