feat: add PrintRoutes() method for debugging routes #1034
+488
−0
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.
Addresses #332
Motivation
When building applications with many routes spread across multiple files and packages, it's helpful to see all registered routes at startup for debugging. This is especially useful during development and when routes aren't behaving as expected. Other popular routers like Gin provide similar functionality.
Changes
PrintRoutes()method to print routes to stdoutPrintRoutesWithWriter(w io.Writer)for flexible output[METHOD ] /pathwith alignmentchi.Walk()to traverse the route tree_examples/debug/Example Usage
Output:
Testing
go test ./... -vAll tests pass
Example
cd _examples/debug go run main.goPrints all registered routes before starting the server.
Backward Compatibility
This is a purely additive change with no breaking changes. All existing code continues to work without modification.
Checklist
chi.Walk()functionRelated Issues
Closes #332
Note: This is part of an academic project where I need to contribute features to open-source Go projects. I chose chi because it's actively maintained, and this feature genuinely helps developers during debugging. I'm excited to contribute to the chi community!