service/api/message/response/HYGBaseResponse.go

47 lines
914 B
Go

package response
import (
"net/http"
"service/api/errcode"
"github.com/gin-gonic/gin"
)
const (
StatusCodeSuccess = "000000"
StatusCodeFail = "999999"
StatusCodeInnerError = "-1"
)
const (
MsgSuccess = "业务成功"
)
type HygBaseResponse struct {
StatusCode string `json:"statusCode"`
StatusText string `json:"statusText"`
Data any `json:"data"`
}
func ReplyOk(ctx *gin.Context, data any) {
ctx.JSON(http.StatusOK, HygBaseResponse{
StatusCode: StatusCodeSuccess,
StatusText: MsgSuccess,
Data: data,
})
}
func ReplyErrorMsg(ctx *gin.Context, msg string) {
ctx.AbortWithStatusJSON(http.StatusOK, HygBaseResponse{
StatusCode: StatusCodeFail,
StatusText: msg,
})
}
func ReplyErrCodeMsg(ctx *gin.Context, ec errcode.ErrCode) {
ctx.AbortWithStatusJSON(http.StatusOK, HygBaseResponse{
StatusCode: StatusCodeFail,
StatusText: errcode.ErrCodeMsgMap[ec],
})
}