helpers

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultAPICacheMaxAge represents the default cache duration used by some
	// API endpoints.
	DefaultAPICacheMaxAge = 5 * time.Minute
)

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 RenderErrorJSON added in v0.2.0

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 added in v0.2.0

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