helpers

package
v0.0.0-...-cab28d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

func BuildCacheControlHeader(cacheMaxAge time.Duration) string

BuildCacheControlHeader builds an http cache header using the max age duration provided.

func GetPagination

func GetPagination(qs url.Values, defaultLimit, maxLimit int) (*hub.Pagination, error)

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

func RenderJSON(w http.ResponseWriter, dataJSON []byte, cacheMaxAge time.Duration, code int)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL