Closed ghost closed 8 years ago
This is ready, now we need a new router (or a wrapper around existing router) that would support the generated format.
Good! Be quick!
Some early version of routes generation has been implemented. Packages routes
and server
were removed from the skeleton
app.
TODO: add support of custom 404 and 405 errors without use of ugly global variables in the router. I'm thinking about adding an optional third parameter to the route:
//@get /errors/404 SOME_PARAMETER_HERE
func (c *App) Error404() http.Handler {
...
}
We'll use it to let a router know we want this action to be used in case of SOME_PARAMETER_HERE
(e.g. error404
or error405
).
Very good you do !
It is more easy to set the route.
By the way, What is the effect on the label of the route
?
And How to use the SOME_PARAMETER_HERE
I'm working on the next iteration of Goal and rethinking everything. At the moment I'm undecided how far we want to go with the code generation. Do we really need the feature this GH issue introduces? Or do we have to roll back to the routes/routes.go
file? I'd like to keep a balance between automation and Go style simplicity / clarity, not turn Goal into something magical. Opinions and thoughts are welcome.
Routes in Goal
Goal's
routes
package in the auto generatedskeleton
app is nothing more than a globalList
variable and calls to the default router:routes
package and write there whatever code he/she needs.r.Get
will be compiled,r.Gte
wont be;h.Controller.Action
will,h.Controller.Atcion
wont, etc).routes.go
to reflect that addition.routes.go
(so we'll have to introduce Goal specific code or convention).Proposal
Use annotation like syntax. E.g. in Bottle.py there is:
There are no annotations in Go, but other tools such as
go generate
andgo build
use tags in comments. That's what we can do, too:Import of actions
Controllers end-developer embeds may include actions with routes. Those can be prefixed as follows:
Result of generation
It is supposed the generated code will be similar to:
This
Routes
then can be used by the router (after importing the package where it's located).For now the variable should be located within generated
handlers
package (as it is easy to implement). After MVP version will require generation of a newroutes
package in./assets/
.Reverse routing
We'll use controllers to generate both
routes
andreverse routes
. A new issue must be open for the latter.