2026-05-21 15:20:12 +08:00
|
|
|
package response
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Body struct {
|
2026-06-01 19:08:43 +08:00
|
|
|
Code int `json:"code"`
|
|
|
|
|
Msg string `json:"msg"`
|
|
|
|
|
Data any `json:"data,omitempty"`
|
2026-05-21 15:20:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func OK(c *gin.Context, data any) {
|
|
|
|
|
c.JSON(http.StatusOK, Body{
|
2026-06-01 19:08:43 +08:00
|
|
|
Code: 200,
|
|
|
|
|
Msg: "操作成功",
|
|
|
|
|
Data: data,
|
2026-05-21 15:20:12 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Fail(c *gin.Context, httpStatus int, code int, message string) {
|
|
|
|
|
c.JSON(httpStatus, Body{
|
2026-06-01 19:08:43 +08:00
|
|
|
Code: code,
|
|
|
|
|
Msg: message,
|
2026-05-21 15:20:12 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func BadRequest(c *gin.Context, message string) {
|
|
|
|
|
Fail(c, http.StatusBadRequest, 40000, message)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func InternalError(c *gin.Context, message string) {
|
|
|
|
|
Fail(c, http.StatusInternalServerError, 50000, message)
|
|
|
|
|
}
|