自定義**Controller**?是一個直接或間接嵌入了?`*revel.Controller`?的struct。
典型用法:
~~~
type AppController struct {
*revel.Controller
}
~~~
`*revel.Controller`?在你自定義的struct中必須是第一個嵌入的類型
`revel.Controller`?用于請求的上下文,包含了請求與響應數據,請到?[the godoc](http://gorevel.cn/docs/docs/godoc/controller.html)?查看完整內容, 下面是一個定義 (以及輔助類型的定義):
~~~
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
}
~~~
作為HTTP請求處理的一部分,Revel實例化一個控制器,設置所有`revel.Controller`嵌入的屬性, 因此, Revel 不在請求之間共享實例,對于每個請求的處理,控制器都是獨立的。