| 12345678910111213141516171819202122 |
- package controller
- import (
- "net/http"
- "github.com/gin-gonic/gin"
- )
- // 返回状态码和错误信息
- func respondError(c *gin.Context, code uint, err error) {
- c.JSON(http.StatusOK, gin.H{"code": code, "message": err.Error()})
- }
- // 返回状态码 500 和错误信息
- func respondUnknownError(c *gin.Context, err error) {
- respondError(c, http.StatusInternalServerError, err)
- }
- // 返回状态码 200 和数据
- func respondOK(c *gin.Context, data any) {
- c.JSON(http.StatusOK, gin.H{"code": 200, "data": data})
- }
|