1. type Controller struct {
  2. // context data
  3. Ctx *context.Context //
  4. Data map[interface{}]interface{}
  5. AppController interface{}
  6. // template data
  7. TplName string //模板名称
  8. ViewPath string
  9. Layout string //
  10. LayoutSections map[string]string // the key is the section name and the value is the template name
  11. TplPrefix string
  12. TplExt string
  13. EnableRender bool
  14. XSRFExpire int
  15. EnableXSRF bool
  16. // session
  17. CruSession session.Store
  18. // contains filtered or unexported fields
  19. }

接口

  1. type ControllerInterface interface {
  2. Init(ct *context.Context, controllerName, actionName string, app interface{})
  3. Prepare() //函数执行之前执行,可以做一些检查,比如说权限
  4. Get()
  5. Post()
  6. Delete()
  7. Put()
  8. Head()
  9. Patch()
  10. Options()
  11. Trace()
  12. Finish() //记录一些日志类动作
  13. Render() error
  14. XSRFToken() string
  15. CheckXSRFCookie() bool
  16. HandlerFunc(fn string) bool
  17. URLMapping()
  18. }

方法

  1. type Controller
  2. func (c *Controller) Abort(code string)
  3. func (c *Controller) CheckXSRFCookie() bool
  4. func (c *Controller) CustomAbort(status int, body string)
  5. func (c *Controller) DelSession(name interface{})
  6. func (c *Controller) Delete()
  7. func (c *Controller) DestroySession()
  8. func (c *Controller) Finish()
  9. func (c *Controller) Get()
  10. func (c *Controller) GetBool(key string, def ...bool) (bool, error)
  11. func (c *Controller) GetControllerAndAction() (string, string)
  12. func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader, error)
  13. func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error)
  14. func (c *Controller) GetFloat(key string, def ...float64) (float64, error)
  15. func (c *Controller) GetInt(key string, def ...int) (int, error)
  16. func (c *Controller) GetInt16(key string, def ...int16) (int16, error)
  17. func (c *Controller) GetInt32(key string, def ...int32) (int32, error)
  18. func (c *Controller) GetInt64(key string, def ...int64) (int64, error)
  19. func (c *Controller) GetInt8(key string, def ...int8) (int8, error)
  20. func (c *Controller) GetSecureCookie(Secret, key string) (string, bool)
  21. func (c *Controller) GetSession(name interface{}) interface{}
  22. func (c *Controller) GetString(key string, def ...string) string
  23. func (c *Controller) GetStrings(key string, def ...[]string) []string
  24. func (c *Controller) GetUint16(key string, def ...uint16) (uint16, error)
  25. func (c *Controller) GetUint32(key string, def ...uint32) (uint32, error)
  26. func (c *Controller) GetUint64(key string, def ...uint64) (uint64, error)
  27. func (c *Controller) GetUint8(key string, def ...uint8) (uint8, error)
  28. func (c *Controller) HandlerFunc(fnname string) bool
  29. func (c *Controller) Head()
  30. func (c *Controller) Init(ctx *context.Context, controllerName, actionName string, app interface{})
  31. func (c *Controller) Input() url.Values
  32. func (c *Controller) IsAjax() bool
  33. func (c *Controller) Mapping(method string, fn func())
  34. func (c *Controller) Options()
  35. func (c *Controller) ParseForm(obj interface{}) error
  36. func (c *Controller) Patch()
  37. func (c *Controller) Post()
  38. func (c *Controller) Prepare()
  39. func (c *Controller) Put()
  40. func (c *Controller) Redirect(url string, code int)
  41. func (c *Controller) Render() error
  42. func (c *Controller) RenderBytes() ([]byte, error)
  43. func (c *Controller) RenderString() (string, error)
  44. func (c *Controller) SaveToFile(fromfile, tofile string) error
  45. func (c *Controller) ServeFormatted(encoding ...bool)
  46. func (c *Controller) ServeJSON(encoding ...bool)
  47. func (c *Controller) ServeJSONP()
  48. func (c *Controller) ServeXML()
  49. func (c *Controller) ServeYAML()
  50. func (c *Controller) SessionRegenerateID()
  51. func (c *Controller) SetData(data interface{})
  52. func (c *Controller) SetSecureCookie(Secret, name, value string, others ...interface{})
  53. func (c *Controller) SetSession(name interface{}, value interface{})
  54. func (c *Controller) StartSession() session.Store
  55. func (c *Controller) StopRun()
  56. func (c *Controller) Trace()
  57. func (c *Controller) URLFor(endpoint string, values ...interface{}) string
  58. func (c *Controller) URLMapping()
  59. func (c *Controller) XSRFFormHTML() string func (c *Controller) XSRFToken() string
文档更新时间: 2023-07-11 17:20   作者:张尚