Documentation ¶
Index ¶
- Constants
- func BuildCacheControlHeader(cacheMaxAge time.Duration) string
- func GetPagination(qs url.Values, defaultLimit, maxLimit int) (*hub.Pagination, error)
- func RenderErrorJSON(w http.ResponseWriter, err error)
- func RenderErrorWithCodeJSON(w http.ResponseWriter, err error, code int)
- func RenderJSON(w http.ResponseWriter, dataJSON []byte, cacheMaxAge time.Duration, code int)
Constants ¶
const ( // DefaultAPICacheMaxAge represents the default cache duration used by some // API endpoints. DefaultAPICacheMaxAge = 5 * time.Minute // PaginationDefaultLimit represents the default limit used for pagination. PaginationDefaultLimit = 20 // PaginationMaxLimit represents the default maximum limit used for // pagination. PaginationMaxLimit = 60 // PaginationTotalCount represents a header used to indicate the number of // entries available for pagination purposes. PaginationTotalCount = "Pagination-Total-Count" )
Variables ¶
This section is empty.
Functions ¶
func BuildCacheControlHeader ¶
BuildCacheControlHeader builds an http cache header using the max age duration provided.
func GetPagination ¶
GetPagination is a helper that extracts the pagination information from the query string values provided.
func RenderErrorJSON ¶
func RenderErrorJSON(w http.ResponseWriter, err error)
RenderErrorJSON is a helper to write the error provided to the given http response writer as json setting the appropriate content type.
func RenderErrorWithCodeJSON ¶
func RenderErrorWithCodeJSON(w http.ResponseWriter, err error, code int)
RenderErrorWithCodeJSON is a helper to write the error provided to the given http response writer as json setting the appropriate content type. Unlike RenderErrorJSON, which decides what status code to use based on the type of the error provided, this methods expects the status code and the error msg will be always sent to the requester.
func RenderJSON ¶
RenderJSON is a helper to write the json data provided to the given http response writer, setting the appropriate content type, cache and status code.
Types ¶
This section is empty.