统一初始beego mvc 的方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
717 B

  1. package json
  2. type Json struct {
  3. Code int `json:"code"`
  4. Data interface{} `json:"data"`
  5. Msg string `json:"msg"`
  6. Status bool `json:"status"`
  7. }
  8. func GetDefaultJsonSuccessResponse() *Json {
  9. return &Json{
  10. Code: 0,
  11. Data: nil,
  12. Msg: "ok",
  13. Status: true,
  14. }
  15. }
  16. func GetDefaultJsonFailedResponse() *Json {
  17. return &Json{
  18. Code: 1,
  19. Data: nil,
  20. Msg: "unknow",
  21. Status: false,
  22. }
  23. }
  24. func New(status bool, code int, msg string, data ...interface{}) *Json {
  25. if len(data) > 0 {
  26. return &Json{
  27. Code: code,
  28. Data: data[0],
  29. Msg: msg,
  30. Status: status,
  31. }
  32. } else {
  33. return &Json{
  34. Code: code,
  35. Data: nil,
  36. Msg: msg,
  37. Status: status,
  38. }
  39. }
  40. }