This commit is contained in:
lingxiao865
2026-02-10 09:30:37 +08:00
commit 13d1175057
15 changed files with 1728 additions and 0 deletions

42
utils/response.go Normal file
View File

@@ -0,0 +1,42 @@
package utils
import (
"github.com/gofiber/fiber/v2"
)
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
func Success(c *fiber.Ctx, data interface{}) error {
return c.JSON(Response{
Code: 200,
Message: "success",
Data: data,
})
}
func Error(c *fiber.Ctx, code int, message string) error {
return c.Status(code).JSON(Response{
Code: code,
Message: message,
})
}
func BadRequest(c *fiber.Ctx, message string) error {
return Error(c, fiber.StatusBadRequest, message)
}
func Unauthorized(c *fiber.Ctx, message string) error {
return Error(c, fiber.StatusUnauthorized, message)
}
func NotFound(c *fiber.Ctx, message string) error {
return Error(c, fiber.StatusNotFound, message)
}
func InternalServerError(c *fiber.Ctx, message string) error {
return Error(c, fiber.StatusInternalServerError, message)
}