自定義Controller 是一個(gè)直接或間接嵌入了 *revel.Controller
的struct。
典型用法:
type AppController struct {
*revel.Controller
}
*revel.Controller
在你自定義的struct中必須是第一個(gè)嵌入的類型
revel.Controller
用于請(qǐng)求的上下文,包含了請(qǐng)求與響應(yīng)數(shù)據(jù),請(qǐng)到 the godoc 查看完整內(nèi)容, 下面是一個(gè)定義 (以及輔助類型的定義):
type Controller struct {
Name string // 控制器名稱, 比如: "Application"
Type *ControllerType // 控制器類型描述
MethodType *MethodType // 控制器方法描述
AppController interface{} // 控制器實(shí)例
Request *Request
Response *Response
Result Result
Flash Flash // 用戶 cookie, 在請(qǐng)求之后清空
Session Session // Session, 保存在cookie中,簽名。
Params *Params // URL和表單中的參數(shù)(包擴(kuò) multipart).
Args map[string]interface{} // 每個(gè)請(qǐng)求的暫存空間
RenderArgs map[string]interface{} // 傳遞給模板的參數(shù)
Validation *Validation // 數(shù)據(jù)驗(yàn)證幫助器
}
// 統(tǒng)一的請(qǐng)求參數(shù)包裝
// 包括:
// - 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請(qǐng)求處理的一部分,Revel實(shí)例化一個(gè)控制器,設(shè)置所有revel.Controller
嵌入的屬性, 因此, Revel 不在請(qǐng)求之間共享實(shí)例,對(duì)于每個(gè)請(qǐng)求的處理,控制器都是獨(dú)立的。
更多建議: