This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
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.
Hello I am doing a small feature that add the resource name to the RouteInfo struct as asked in the issue #1762.
Files changed
routes_info.go
route_mappings.go
route_mappings_test.go
How I have implemented that
In the
route_mapping.go
file the way to register a new resource is to call app.Resource right ?To be simple as possible I am just counting the number of routes before all resources handlers are added. Then after all handlers are added I am looping over all routes after the index saved and set the field
resourceName
tort.Name()
.The Resource method look like this:
I have also reordered all the way routes are added to be more concise. Now first there is non optional routes (the Resource interface methods) and then
newable
andeditable
. Edit: seems to have an order dependance with Show and New in theTest_ResourceOnResource
test function so the order is now identical as before.The
resourceName
is a field that will be set only if the handler is part of a resource.The RouteInfo struct now look like this:
To not polluate the Stringer implementation I have set a jsontag to omitempty.
Test add
A new test named
Test_App_Routes_Resource
check the resourceName on each routes of the resource.