feat: user buy media

This commit is contained in:
Rogee
2024-12-10 11:21:55 +08:00
parent 21840c3adf
commit e3ef31037c
17 changed files with 201 additions and 132 deletions

View File

@@ -2,18 +2,31 @@ package errorx
import (
"fmt"
"net/http"
"github.com/gofiber/fiber/v3"
)
type Response struct {
Code int `json:"code"`
Message string `json:"message"`
StatusCode int `json:"-"`
Code int `json:"code"`
Message string `json:"message"`
}
func Wrap(err error) Response {
return Response{http.StatusInternalServerError, http.StatusInternalServerError, err.Error()}
}
func (r Response) Error() string {
return fmt.Sprintf("%d: %s", r.Code, r.Message)
return fmt.Sprintf("[%d] %s", r.Code, r.Message)
}
func (r Response) Response(ctx fiber.Ctx) error {
return ctx.Status(r.Code).JSON(r)
}
var (
RequestParseError = Response{400, "请求解析错误"}
InternalError = Response{500, "内部错误"}
RequestParseError = Response{http.StatusBadRequest, http.StatusBadRequest, "请求解析错误"}
InternalError = Response{http.StatusInternalServerError, http.StatusInternalServerError, "内部错误"}
UserBalanceNotEnough = Response{http.StatusPaymentRequired, 1001, "余额不足,请充值"}
)