e6956aa001
- React frontend with route-level code splitting - Backend rebranded from Baihu to TaskPool - DB brand migration script and local compatibility
60 lines
982 B
Go
60 lines
982 B
Go
package utils
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type Response struct {
|
|
Code int `json:"code"`
|
|
Msg string `json:"msg"`
|
|
Data interface{} `json:"data,omitempty"`
|
|
}
|
|
|
|
func Success(c *gin.Context, data interface{}) {
|
|
c.JSON(http.StatusOK, Response{
|
|
Code: 200,
|
|
Msg: "success",
|
|
Data: data,
|
|
})
|
|
}
|
|
|
|
func SuccessMsg(c *gin.Context, msg string) {
|
|
c.JSON(http.StatusOK, Response{
|
|
Code: 200,
|
|
Msg: msg,
|
|
})
|
|
}
|
|
|
|
func Error(c *gin.Context, code int, msg string) {
|
|
c.JSON(http.StatusOK, Response{
|
|
Code: code,
|
|
Msg: msg,
|
|
})
|
|
}
|
|
|
|
func BadRequest(c *gin.Context, msg string) {
|
|
Error(c, 400, msg)
|
|
}
|
|
|
|
func Unauthorized(c *gin.Context, msg string) {
|
|
Error(c, 401, msg)
|
|
}
|
|
|
|
func Forbidden(c *gin.Context, msg string) {
|
|
Error(c, 403, msg)
|
|
}
|
|
|
|
func NotFound(c *gin.Context, msg string) {
|
|
Error(c, 404, msg)
|
|
}
|
|
|
|
func TooManyRequests(c *gin.Context, msg string) {
|
|
Error(c, 429, msg)
|
|
}
|
|
|
|
func ServerError(c *gin.Context, msg string) {
|
|
Error(c, 500, msg)
|
|
}
|