Documentation
¶
Index ¶
- Variables
- func Bind(r *http.Request, dest any) error
- func Handler(h HandlerFunc) http.HandlerFunc
- func Render(w http.ResponseWriter, r *http.Request, response any) error
- type Binder
- type ErrorResponse
- type HandlerFunc
- type Hex
- type HexSlice
- type Pagination
- type PaginationOptions
- type PaginationRequest
- type PaginationResponse
- type Role
- type RoleSlice
- type Uint64Slice
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotFound = &ErrorResponse{Code: 404, Status: "Resource not found."}
Functions ¶
func Handler ¶
func Handler(h HandlerFunc) http.HandlerFunc
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Err error `json:"-"` // low-level runtime error
Code int `json:"-"` // http response status code
Status string `json:"status"` // user-level status message
Message string `json:"error,omitempty"` // application-level error message, for debugging
}
func BadRequestError ¶
func BadRequestError(err error) *ErrorResponse
func Error ¶
func Error(err error) *ErrorResponse
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
func (*ErrorResponse) Render ¶
func (e *ErrorResponse) Render(w http.ResponseWriter, r *http.Request) error
type HandlerFunc ¶
type HandlerFunc func(http.ResponseWriter, *http.Request) error
type Pagination ¶
type Pagination interface {
Page() uint64
PerPage() uint64
// SliceBounds returns safe [start,end) bounds for slicing a collection with the given total length.
SliceBounds(total uint64) (start, end uint64)
}
Pagination is the resolved (non-optional) pagination configuration. It is only constructible outside this package via PaginationRequest.ToPagination.
type PaginationOptions ¶
type PaginationRequest ¶
type PaginationRequest struct {
Set bool `json:"-"`
Page *uint64 `json:"page,omitempty"`
PerPage *uint64 `json:"per_page,omitempty"`
}
func (*PaginationRequest) Bind ¶
func (p *PaginationRequest) Bind(value string) error
func (PaginationRequest) ToPagination ¶
func (p PaginationRequest) ToPagination(opts PaginationOptions) (Pagination, error)
func (*PaginationRequest) UnmarshalJSON ¶
func (p *PaginationRequest) UnmarshalJSON(data []byte) error
type PaginationResponse ¶
type PaginationResponse struct {
Page uint64 `json:"page"`
PerPage uint64 `json:"per_page"`
Total uint64 `json:"total"`
TotalPages uint64 `json:"total_pages"`
}
func PaginationResponseFromPagination ¶
func PaginationResponseFromPagination(p Pagination, total uint64) PaginationResponse
type Uint64Slice ¶
type Uint64Slice []uint64
func (*Uint64Slice) Bind ¶
func (us *Uint64Slice) Bind(value string) error
Click to show internal directories.
Click to hide internal directories.