Files
app-api/internal/response/response.go
T

37 lines
653 B
Go
Raw Normal View History

2026-05-21 15:20:12 +08:00
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Body struct {
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{
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{
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)
}