Go Revel - Controllers(控制器)
Controller(控制器)整個revel都是圍繞它處理所有請求
控制器可以是任何直接或間接內嵌了`*revel.Controller`類型的結構,如:
type AppController struct {
*revel.Controller
}
`*revel.Controller`必須位于結構的第一個字段,并且是匿名內嵌方式。
`revel.Controller`是一次請求的上下文,包含請求數據及返回數據。
type Controller struct {
Name string // controller名稱
Type *ControllerType // controller的類型描述
MethodType *MethodType // 被調用的action的類型描述
AppController interface{} // controller實例
Request *Request // 請求體
Response *Response // 返回體
Result Result // server處理的數據
Flash Flash // flash信息,生命周期為一個請求
Session Session // 存儲cookies
Params *Params // 請求的參數
Args map[string]interface{} // 每一個請求action傳入的參數
RenderArgs map[string]interface{} // 傳遞給模板的參數
Validation *Validation // 數據驗證器
}
// 請求參數
// 包含:
// - URL 請求URL
// - Form 表單值
// - File 上傳的文件
type Params struct {
url.Values
Files map[string][]*multipart.FileHeader
}
// 請求體
type Request struct {
*http.Request
ContentType string
}
// server處理的返回體
type Response struct {
Status int
ContentType string
Headers http.Header
Cookies []*http.Cookie
Out http.ResponseWriter
}
對于每一個請求,Revel都會實例化一個對應的`Controller`,并為內嵌的`*revel.Controller`結構的相應字段賦值,因此,Revel并不會在不同的請求之間共享`Controller`
具體請移步:
Go Revel - server.go 源碼分析 http://www.rzrgm.cn/hangxin1940/p/3265538.html
Go Revel - Filter(過濾器) http://www.rzrgm.cn/hangxin1940/p/3266311.html
浙公網安備 33010602011771號