base_api_controller.go 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package controllers
  2. import (
  3. "Data_Upload_Api/enums"
  4. )
  5. type BaseAPIController struct {
  6. BaseController
  7. }
  8. // func (this *BaseAPIController) Prepare() {
  9. // this.BaseController.Prepare()
  10. // beego.Trace("============================================================")
  11. // beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
  12. // beego.Trace("session : %v", this.GetSession("info"))
  13. // this.SetSession("info", time.Now().Format("2006/01/02 15:04:05"))
  14. // beego.Trace("============================================================")
  15. // }
  16. // 输出数据格式化
  17. /*
  18. success json:
  19. {
  20. "state": 1,
  21. "code": 0,
  22. "data": json,
  23. }
  24. fail json:
  25. {
  26. "state": 0,
  27. "code": int,
  28. "msg": string,
  29. }
  30. */
  31. func (this *BaseAPIController) ServeSuccessJSON(data map[string]interface{}) {
  32. this.Data["json"] = enums.MakeSuccessResponseJSON(data)
  33. this.ServeJSON()
  34. }
  35. func (this *BaseAPIController) ServeFailJSONWithSGJErrorCode(code int) {
  36. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(code)
  37. this.ServeJSON()
  38. }
  39. func (this *BaseAPIController) ServeFailJSONWithSGJError(err *enums.SGJError) {
  40. this.Data["json"] = enums.MakeFailResponseJSONWithSGJError(err)
  41. this.ServeJSON()
  42. }
  43. func (this *BaseAPIController) ServeFailJsonSend(code int, msg string) {
  44. this.Data["json"] = enums.MakeFailResponseJSON(msg, code)
  45. this.ServeJSON()
  46. }
  47. type BaseAuthAPIController struct {
  48. BaseAPIController
  49. }
  50. func (this *BaseAuthAPIController) Prepare() {
  51. this.BaseAPIController.Prepare()
  52. }
  53. type BaseServeAPIController struct {
  54. BaseAPIController
  55. }
  56. func (this *BaseServeAPIController) Prepare() {
  57. this.BaseAPIController.Prepare()
  58. }