tt/utils/response.go
2024-05-28 08:47:31 +08:00

31 lines
546 B
Go

package utils
import (
"github.com/gin-gonic/gin"
"net/http"
)
type Response struct {
Code int `json:"code"` // if request is success
Msg string `json:"msg"`
Data interface{} `json:"data"` // response data
}
func ResponseOK(c *gin.Context, errMsg string, data interface{}) {
c.JSON(http.StatusOK, Response{
Code: 0,
Msg: errMsg,
Data: data,
})
return
}
func ResponseError(c *gin.Context, errMsg string, data interface{}) {
c.JSON(http.StatusOK, Response{
Code: 400,
Msg: errMsg,
Data: data,
})
return
}