Documentation
¶
Index ¶
- Constants
- func CreateHealthChecker(db checkers.SQLPinger, disableLog bool) (*health.Health, error)
- func RespondWithError(w http.ResponseWriter, code int, err error)
- func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})
- func TransformValidationError(err error) error
- type ErrResponse
- type PaginationQuery
- type PaginationResponse
Constants ¶
const ( MethodGET = "GET" MethodPOST = "POST" MethodPUT = "PUT" MethodDELETE = "DELETE" BearerSchema = "Bearer " )
Common HTTP methods and header values
Variables ¶
This section is empty.
Functions ¶
func CreateHealthChecker ¶
CreateHealthChecker returns a health checker instance with all checkers registered.
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, code int, err error)
RespondWithError provides an auxiliary function to handle all failed HTTP requests.
func RespondWithJSON ¶
func RespondWithJSON(w http.ResponseWriter, code int, payload interface{})
RespondWithJSON provides an auxiliary function to return an HTTP response with JSON content and an HTTP status code.
func TransformValidationError ¶
TransformValidationError accepts an error from validation and attempts to transform the error message to a more human-readable format.
Types ¶
type ErrResponse ¶
type ErrResponse struct {
Error string `json:"error"`
}
ErrResponse defines an HTTP error response.
type PaginationQuery ¶
PaginationQuery defines the structure containing pagination request information from client HTTP requests.
func ParsePaginationQueryParams ¶
func ParsePaginationQueryParams(req *http.Request) (PaginationQuery, error)
ParsePaginationQueryParams parses pagination values from an HTTP request returning an error upon failure.
type PaginationResponse ¶
type PaginationResponse struct { Order string `json:"order"` Reverse bool `json:"reverse"` Page int64 `json:"page"` Limit int64 `json:"limit"` Total int64 `json:"total"` PrevURI string `json:"prev_uri"` NextURI string `json:"next_uri"` Results interface{} `json:"results"` }
PaginationResponse defines a generic type encapsulating a paginated response. Client should not rely on decoding into this type as the Results is an interface.
func NewPaginationResponse ¶
func NewPaginationResponse(pq PaginationQuery, prev, next, total int64, results interface{}) PaginationResponse