加载中...

概要


自定义Controller 是一个直接或间接嵌入了 *revel.Controller 的struct。

典型用法:

  1. type AppController struct {
  2. *revel.Controller
  3. }

*revel.Controller 在你自定义的struct中必须是第一个嵌入的类型

revel.Controller 用于请求的上下文,包含了请求与响应数据,请到 the godoc 查看完整内容, 下面是一个定义 (以及辅助类型的定义):

  1. type Controller struct {
  2. Name string // 控制器名称, 比如: "Application"
  3. Type *ControllerType // 控制器类型描述
  4. MethodType *MethodType // 控制器方法描述
  5. AppController interface{} // 控制器实例
  6. Request *Request
  7. Response *Response
  8. Result Result
  9. Flash Flash // 用户 cookie, 在请求之后清空
  10. Session Session // Session, 保存在cookie中,签名。
  11. Params *Params // URL和表单中的参数(包扩 multipart).
  12. Args map[string]interface{} // 每个请求的暂存空间
  13. RenderArgs map[string]interface{} // 传递给模板的参数
  14. Validation *Validation // 数据验证帮助器
  15. }
  16. // 统一的请求参数包装
  17. // 包括:
  18. // - URL 查询字符串
  19. // - Form 表单字段
  20. // - File 文件上传
  21. type Params struct {
  22. url.Values
  23. Files map[string][]*multipart.FileHeader
  24. }
  25. type Request struct {
  26. *http.Request
  27. ContentType string
  28. }
  29. type Response struct {
  30. Status int
  31. ContentType string
  32. Headers http.Header
  33. Cookies []*http.Cookie
  34. Out http.ResponseWriter
  35. }

作为HTTP请求处理的一部分,Revel实例化一个控制器,设置所有revel.Controller嵌入的属性, 因此, Revel 不在请求之间共享实例,对于每个请求的处理,控制器都是独立的。


还没有评论.