2024-06-15 11:41:12 +08:00
|
|
|
package response
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"service/api/errcode"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2024-06-21 18:25:24 +08:00
|
|
|
StatusCodeSuccess = "000000"
|
|
|
|
StatusCodeFail = "999999"
|
|
|
|
StatusCodeInnerError = "-1"
|
2024-06-15 11:41:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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],
|
|
|
|
})
|
|
|
|
}
|