base_api_controller.go 977B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package controllers
  2. import (
  3. "Kya_New/enums"
  4. "fmt"
  5. )
  6. type BaseAPIController struct {
  7. BaseController
  8. }
  9. func (this *BaseAPIController) ServeSuccessJSON(data map[string]interface{}) {
  10. this.Data["json"] = enums.MakeSuccessResponseJSON(data)
  11. this.ServeJSON()
  12. }
  13. func (this *BaseAPIController) ServeFailJSONWithSGJErrorCode(code int) {
  14. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(code)
  15. this.ServeJSON()
  16. }
  17. func (this *BaseAPIController) ServeFailJSONWithSGJError(err *enums.SGJError) {
  18. this.Data["json"] = enums.MakeFailResponseJSONWithSGJError(err)
  19. this.ServeJSON()
  20. }
  21. func (this *BaseAPIController) ServeFailJsonSend(code int, msg string) {
  22. fmt.Println("code", code)
  23. this.Data["json"] = enums.MakeFailResponseJSON(msg, code)
  24. this.ServeJSON()
  25. }
  26. type BaseAuthAPIController struct {
  27. BaseAPIController
  28. }
  29. type BaseServeAPIController struct {
  30. BaseAPIController
  31. }
  32. func (this *BaseServeAPIController) Prepare() {
  33. this.BaseAPIController.Prepare()
  34. }