May 15, 2021 Revel
Revel from Rails and Play! Many mature design ideas have been absorbed, and many of the same ideas have been used in the design and interface of the framework.
Revel supports MVC design patterns with simple conventions that are lightweight and efficient to develop.
Some nice MVC structure overviews, like play! frameworks that exactly match the Level framework.
Here's a basic process for request processing:
Profile:
Revel builds from the top-level Go HTTP server, and he creates a go-routine (lightweight thread) for every incoming request to handle symploy.
Revel does nothing but leave the request to the filter chain, which, when complete, writes the results to the response.
By default, the Revel handler registers
"/"
to accept all requested connections. H
owever, the application is free to rewrite this behavior - for example, you can use the existing http. H
andlers, not Revel, re-implements this feature.
Refer to the
FAQ for details.
Filters implement most of Revel's request processing capabilities, and filters have a simple, easy-to-nest interface.
The "filter chain" is an array of functions, each going to execute the next one until the last filter executes the controller method.
For example, the first filter in the filter chain is
RouterFilter
which determines which action accepts the request and saves it to the controller.
In short, filters and filter chains are like racks.
Each HTTP request, performs an action, processes the request, and writes a response. Related actions are grouped into controllers. The Controller type contains related fields and methods as the context for each request.
As part of HTTP request processing, Revel instantiates your controller and sets the
revel.Controller
properties.
Revel does not share instances between requests.
Controller is
directly or indirectly
*revel.Controller
of Controller's structs.
type AppController struct {
*revel.Controller
}
Action is Controller's approach. The following conditions apply:
For example:
func (c AppController) ShowLogin(username string) revel.Result {
..
return c.Render(username)
}
The program calls
revel.Controller.Render
renders a template and passes a username parameter to the template.
has
ontroller has
many ways to
handle revel.
Result,
the program can also create its own processing methods.
Result conforms to the following interface:
type Result interface {
Apply(req *Request, resp *Response)
}
Typically, nothing responds until
action and
all filters return. A
t this point, Revel writes the response to the headers and cookies.
(for example, set a session cookie) and then call
Result.Apply
write to the actual response.