May 15, 2021 Revel
Custom
Controller is
a directly or indirectly
*revel.Controller
struct.
Typical usage:
type AppController struct {
*revel.Controller
}
*revel.Controller
must be the first embedded type in your custom struct
revel.Controller
is used in the context of the request, which contains request and response data,
please go to the godoc
for the full content, here is a definition (and the definition of the secondary type):
type Controller struct {
Name string // 控制器名称, 比如: "Application"
Type *ControllerType // 控制器类型描述
MethodType *MethodType // 控制器方法描述
AppController interface{} // 控制器实例
Request *Request
Response *Response
Result Result
Flash Flash // 用户 cookie, 在请求之后清空
Session Session // Session, 保存在cookie中,签名。
Params *Params // URL和表单中的参数(包扩 multipart).
Args map[string]interface{} // 每个请求的暂存空间
RenderArgs map[string]interface{} // 传递给模板的参数
Validation *Validation // 数据验证帮助器
}
// 统一的请求参数包装
// 包括:
// - URL 查询字符串
// - Form 表单字段
// - File 文件上传
type Params struct {
url.Values
Files map[string][]*multipart.FileHeader
}
type Request struct {
*http.Request
ContentType string
}
type Response struct {
Status int
ContentType string
Headers http.Header
Cookies []*http.Cookie
Out http.ResponseWriter
}
As part of HTTP request processing, Revel instantiates a controller and sets up
revel.Controller
embeds properties, so Revel does not share instances between requests, and the controller is independent for the processing of each request.