resp.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // gin响应模块
  2. // 秒寻科技
  3. // zt 2024-01-05
  4. package resp
  5. import (
  6. "net/http"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // token过期
  10. func RespTokenExpire(c *gin.Context, err string) {
  11. c.JSON(http.StatusOK, gin.H{
  12. "code": 2001,
  13. "msg": err,
  14. })
  15. }
  16. // 响应失败
  17. func RespFail(c *gin.Context, err string) {
  18. c.JSON(http.StatusOK, gin.H{
  19. "code": 2002,
  20. "msg": err,
  21. })
  22. }
  23. // 响应成功,不返回数据
  24. func RespOk(c *gin.Context) {
  25. c.JSON(http.StatusOK, gin.H{
  26. "code": 2000,
  27. "msg": "success",
  28. })
  29. }
  30. // 响应成功,返回记录ID
  31. func RespToken(c *gin.Context, token string) {
  32. c.JSON(http.StatusOK, gin.H{
  33. "code": 2000,
  34. "msg": "success",
  35. "token": token,
  36. })
  37. }
  38. // 响应成功,返回记录ID
  39. func RespId(c *gin.Context, id int) {
  40. c.JSON(http.StatusOK, gin.H{
  41. "code": 2000,
  42. "msg": "success",
  43. "id": id,
  44. })
  45. }
  46. // 响应成功,返回数据模型
  47. func RespData(c *gin.Context, dataModel interface{}) {
  48. c.JSON(http.StatusOK, gin.H{
  49. "code": 2000,
  50. "msg": "success",
  51. "data": dataModel,
  52. })
  53. }
  54. // 响应成功,返回数据列表
  55. func RespList(c *gin.Context, dataList interface{}) {
  56. c.JSON(http.StatusOK, gin.H{
  57. "code": 2000,
  58. "msg": "success",
  59. "data": dataList,
  60. })
  61. }