Documentation
¶
Index ¶
- Constants
- Variables
- func ErrorStatusCode(err error) int
- func ParseRequest(c *gin.Context, obj any) bool
- func ParseRequestError(c *gin.Context, obj any) error
- func RespondBadRequest(c *gin.Context, err error)
- func RespondConflict(c *gin.Context, err error)
- func RespondData(c *gin.Context, data any)
- func RespondDataMeta(c *gin.Context, data, meta any)
- func RespondDataPages(c *gin.Context, data any, pages int64)
- func RespondError(c *gin.Context, err error)
- func RespondErrorData(c *gin.Context, err error, data any)
- func RespondForbidden(c *gin.Context, err error)
- func RespondInternalError(c *gin.Context, err error)
- func RespondJSON(c *gin.Context, code int, data any)
- func RespondNotFound(c *gin.Context, err error)
- func RespondOK(c *gin.Context)
- func RespondStatusError(c *gin.Context, code int, err error)
- func RespondStatusErrorData(c *gin.Context, code int, err error, data any)
- func RespondTooManyRequests(c *gin.Context, err error)
- func RespondUnauthorized(c *gin.Context, err error)
- func ServeError(c *gin.Context, err error)
- type MetaPages
- type Pagination
- type Response
Constants ¶
View Source
const ( HeaderAcceptLanguage = "Accept-Language" HeaderAuthenticate = "WWW-Authenticate" HeaderAuthorization = "Authorization" HeaderOrigin = "Origin" HeaderContentLength = "Content-Length" HeaderContentType = "Content-Type" HeaderContentLanguage = "Content-Language" HeaderUserAgent = "User-Agent" HeaderDeviceID = "X-Device-ID" HeaderContentTypeOption = "X-Content-Type-Options" )
View Source
const ( StatusSuccess = "success" StatusError = "error" )
Variables ¶
View Source
var ( ErrBadRequest = errors.New("base.bad_request") ErrValidation = errors.New("base.validation") ErrForbidden = errors.New("base.forbidden") ErrNotFound = errors.New("base.not_found") ErrConflict = errors.New("base.conflict") ErrTooManyRequests = errors.New("base.too_many_request") ErrInternalServerError = errors.New("base.internal_server_error") )
View Source
var DefaultPerPage = 10
View Source
var Validator = binding.Validator
Functions ¶
func ErrorStatusCode ¶
func RespondBadRequest ¶
func RespondConflict ¶
func RespondData ¶
func RespondDataMeta ¶
func RespondError ¶
func RespondForbidden ¶
func RespondInternalError ¶
func RespondNotFound ¶
func RespondStatusErrorData ¶
func RespondTooManyRequests ¶
func RespondUnauthorized ¶
func ServeError ¶
Types ¶
type Pagination ¶
type Pagination struct {
Page int `form:"page" json:"page"`
PerPage int `form:"per_page" json:"per_page"`
}
func (Pagination) Limit ¶
func (p Pagination) Limit() int
func (Pagination) LimitOffset ¶
func (p Pagination) LimitOffset() (int, int)
func (Pagination) Offset ¶
func (p Pagination) Offset() int
func (Pagination) Pages ¶
func (p Pagination) Pages(total int64) int64
type Response ¶
type Response struct {
Status string `json:"status"`
Error string `json:"error,omitempty"`
Data any `json:"data,omitempty"`
Meta any `json:"meta,omitempty"`
}
func NewErrorResponse ¶
func NewErrorResponseData ¶
func NewResponse ¶
func NewResponseMeta ¶
Click to show internal directories.
Click to hide internal directories.