Documentation ¶
Index ¶
- Variables
- func EmptyOkHandler(w http.ResponseWriter, r *http.Request)
- func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
- func NotFoundHandler(w http.ResponseWriter, r *http.Request)
- func ReqParamBool(r *http.Request, key string, def bool) bool
- func ReqParamInt(r *http.Request, key string, def int) int
- func RespondWithDispatchTypeError(w http.ResponseWriter, got interface{})
- func RespondWithError(w http.ResponseWriter, err error)
- func WriteErrResponse(w http.ResponseWriter, code int, err error) error
- func WriteMessageResponse(w http.ResponseWriter, message string, data interface{}) error
- func WritePageResponse(w http.ResponseWriter, data interface{}, r *http.Request, p Page) error
- func WriteResponse(w http.ResponseWriter, data interface{}) error
- type APIError
- type Meta
- type Order
- type OrderBy
- type Page
- type Response
Constants ¶
This section is empty.
Variables ¶
var ( // OrderASC defines the ascending order keyword OrderASC = "asc" // OrderDESC defines the descending order keyword OrderDESC = "desc" )
var ( // DefaultPageSize is the number NewPage DefaultPageSize = 50 // DefaultMaxPageSize is the max size a page can be by default, set to -1 to // ignore maximum sizes DefaultMaxPageSize = 100 )
Functions ¶
func EmptyOkHandler ¶
func EmptyOkHandler(w http.ResponseWriter, r *http.Request)
EmptyOkHandler is an empty 200 response, often used for OPTIONS requests that responds with headers set in addCorsHeaders
func HealthCheckHandler ¶
func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
HealthCheckHandler is a basic "hey I'm fine" for load balancers & co TODO - add Database connection & proper configuration checks here for more accurate health reporting
func NotFoundHandler ¶
func NotFoundHandler(w http.ResponseWriter, r *http.Request)
NotFoundHandler is a JSON 404 response
func ReqParamBool ¶
ReqParamBool pulls a boolean parameter from a request form value
func ReqParamInt ¶
ReqParamInt extracts an integer parameter from a request form value
func RespondWithDispatchTypeError ¶ added in v0.10.0
func RespondWithDispatchTypeError(w http.ResponseWriter, got interface{})
RespondWithDispatchTypeError writes an error describing a type mismatch error from using dispatch
func RespondWithError ¶
func RespondWithError(w http.ResponseWriter, err error)
RespondWithError writes the error, with meaningful text, to the http response
func WriteErrResponse ¶
func WriteErrResponse(w http.ResponseWriter, code int, err error) error
WriteErrResponse writes a JSON error response message & HTTP status
func WriteMessageResponse ¶
func WriteMessageResponse(w http.ResponseWriter, message string, data interface{}) error
WriteMessageResponse includes a message with a data response
func WritePageResponse ¶
WritePageResponse wraps response data and pagination information in an envelope and writes it
func WriteResponse ¶
func WriteResponse(w http.ResponseWriter, data interface{}) error
WriteResponse wraps response data in an envelope & writes it
Types ¶
type APIError ¶
APIError is an error that specifies its http status code
func NewAPIError ¶
NewAPIError returns a new APIError
type Meta ¶ added in v0.10.0
type Meta struct { Code int `json:"code,omitempty"` Message string `json:"message,omitempty"` Error string `json:"error,omitempty"` }
Meta is the JSON API response meta object wrapper
type Order ¶
Order represents ordering information for a single key
type OrderBy ¶
type OrderBy []Order
OrderBy represents ordering information
func NewOrderByFromString ¶
NewOrderByFromString converts a commaa delimited string to an OrderBy struct
func OrderByFromRequest ¶
OrderByFromRequest extracts orderBy params from an http request
func OrderByFromRequestWithKeys ¶
OrderByFromRequestWithKeys extracts orderBy params from an http request and only takes the specified keys
func (OrderBy) SetQueryParams ¶
SetQueryParams adds order by info to a url as query parameters
type Page ¶
type Page struct { Number int `json:"page,omitempty"` Size int `json:"pageSize,omitempty"` ResultCount int `json:"resultCount,omitempty"` NextURL string `json:"nextUrl"` PrevURL string `json:"prevUrl"` }
Page represents pagination information
func NewPageFromOffsetAndLimit ¶
NewPageFromOffsetAndLimit converts a offset and Limit to a Page struct
func PageFromRequest ¶
PageFromRequest extracts pagination params from an http request
func (Page) NextPageExists ¶
NextPageExists returns false if the next page.ResultCount is a postive number and the starting offset of the next page exceeds page.ResultCount
func (Page) Offset ¶
Offset calculates the starting index for pagination based on page size & number
func (Page) PrevPageExists ¶
PrevPageExists returns false if the page number is 1