Files
gin_layout/pkg/response/response.go
T
2026-11-06 15:34:35 +08:00

30 lines
491 B
Go

package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
func Success(ctx *gin.Context, data any) {
ctx.JSON(http.StatusOK, Response{
Code: 0,
Message: "success",
Data: data,
})
}
func Error(ctx *gin.Context, status int, message string) {
ctx.AbortWithStatusJSON(status, Response{
Code: status,
Message: message,
Data: nil,
})
}