Documentation ¶
Overview ¶
Library respond creates convreq.HttpResponse objects. These can be returned from HTTP handlers to respond something to the client.
Index ¶
- func Accepted(msg string) internal.HttpResponse
- func BadGateway(msg string) internal.HttpResponse
- func BadRequest(msg string) internal.HttpResponse
- func Bytes(data []byte) internal.HttpResponse
- func Conflict(msg string) internal.HttpResponse
- func Created(msg string) internal.HttpResponse
- func Error(err error) internal.HttpResponse
- func ExpectationFailed(msg string) internal.HttpResponse
- func FailedDependency(msg string) internal.HttpResponse
- func Forbidden(msg string) internal.HttpResponse
- func GatewayTimeout(msg string) internal.HttpResponse
- func Gone(msg string) internal.HttpResponse
- func HTTPVersionNotSupported(msg string) internal.HttpResponse
- func Handler(h http.Handler) internal.HttpResponse
- func Imateapot(msg string) internal.HttpResponse
- func InsufficientStorage(msg string) internal.HttpResponse
- func InternalServerError(msg string) internal.HttpResponse
- func JSON(data interface{}) internal.HttpResponse
- func LengthRequired(msg string) internal.HttpResponse
- func LoopDetected(msg string) internal.HttpResponse
- func MethodNotAllowed(msg string) internal.HttpResponse
- func NetworkAuthenticationRequired(msg string) internal.HttpResponse
- func NoContent(ignored ...string) internal.HttpResponse
- func NotAcceptable(msg string) internal.HttpResponse
- func NotExtended(msg string) internal.HttpResponse
- func NotFound(msg string) internal.HttpResponse
- func NotImplemented(msg string) internal.HttpResponse
- func NotModified(msg string) internal.HttpResponse
- func OverrideResponseCode(hr internal.HttpResponse, code int) internal.HttpResponse
- func PayloadTooLarge(msg string) internal.HttpResponse
- func PreconditionFailed(msg string) internal.HttpResponse
- func PreconditionRequired(msg string) internal.HttpResponse
- func Printf(format string, v ...interface{}) internal.HttpResponse
- func RangeNotSatisfiable(msg string) internal.HttpResponse
- func Reader(r io.Reader) internal.HttpResponse
- func Redirect(code int, url string) internal.HttpResponse
- func RenderTemplate(tpl Template, data interface{}) internal.HttpResponse
- func RequestHeaderFieldsTooLarge(msg string) internal.HttpResponse
- func RequestTimeout(msg string) internal.HttpResponse
- func ResetContent(msg string) internal.HttpResponse
- func ServeContent(name string, modtime time.Time, content io.ReadSeeker) internal.HttpResponse
- func ServeFile(name string) internal.HttpResponse
- func ServeJSON(data interface{}) internal.HttpResponse
- func ServiceUnavailable(msg string) internal.HttpResponse
- func String(data string) internal.HttpResponse
- func TooEarly(msg string) internal.HttpResponse
- func TooManyRequests(msg string) internal.HttpResponse
- func URITooLong(msg string) internal.HttpResponse
- func UnavailableForLegalReasons(msg string) internal.HttpResponse
- func UnprocessableEntity(msg string) internal.HttpResponse
- func UnsupportedMediaType(msg string) internal.HttpResponse
- func UpgradeRequired(msg string) internal.HttpResponse
- func VariantAlsoNegotiates(msg string) internal.HttpResponse
- func WithHeader(hr internal.HttpResponse, header, value string) internal.HttpResponse
- func WithHeaders(hr internal.HttpResponse, headers http.Header) internal.HttpResponse
- type Template
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Accepted ¶ added in v1.2.0
func Accepted(msg string) internal.HttpResponse
Accepted creates a HTTP 202 Accepted response.
func BadGateway ¶ added in v1.2.0
func BadGateway(msg string) internal.HttpResponse
BadGateway creates a HTTP 502 Bad Gateway response.
func BadRequest ¶
func BadRequest(msg string) internal.HttpResponse
BadRequest creates a HTTP 400 Bad Request response.
func Bytes ¶ added in v1.1.0
func Bytes(data []byte) internal.HttpResponse
Bytes creates a response that sends bytes back to the client.
func Conflict ¶ added in v1.2.0
func Conflict(msg string) internal.HttpResponse
Conflict creates a HTTP 409 Conflict response.
func Created ¶ added in v1.2.0
func Created(msg string) internal.HttpResponse
Created creates a HTTP 201 Created response.
func Error ¶
func Error(err error) internal.HttpResponse
Error creates a HTTP 500 Internal Server Error response.
func ExpectationFailed ¶ added in v1.2.0
func ExpectationFailed(msg string) internal.HttpResponse
ExpectationFailed creates a HTTP 417 Expectation Failed response.
func FailedDependency ¶ added in v1.4.0
func FailedDependency(msg string) internal.HttpResponse
FailedDependency creates a HTTP 424 Failed Dependency response.
func Forbidden ¶ added in v1.2.0
func Forbidden(msg string) internal.HttpResponse
Forbidden creates a HTTP 403 Forbidden response.
func GatewayTimeout ¶ added in v1.2.0
func GatewayTimeout(msg string) internal.HttpResponse
GatewayTimeout creates a HTTP 504 Gateway Timeout response.
func Gone ¶ added in v1.2.0
func Gone(msg string) internal.HttpResponse
Gone creates a HTTP 410 Gone response.
func HTTPVersionNotSupported ¶ added in v1.2.0
func HTTPVersionNotSupported(msg string) internal.HttpResponse
HTTPVersionNotSupported creates a HTTP 505 HTTP Version Not Supported response.
func Handler ¶
func Handler(h http.Handler) internal.HttpResponse
Handler creates a response that delegates to a regular http.Handler.
func Imateapot ¶ added in v1.2.0
func Imateapot(msg string) internal.HttpResponse
Imateapot creates a HTTP 418 I'm a teapot response.
func InsufficientStorage ¶ added in v1.2.0
func InsufficientStorage(msg string) internal.HttpResponse
InsufficientStorage creates a HTTP 507 Insufficient Storage response.
func InternalServerError ¶
func InternalServerError(msg string) internal.HttpResponse
InternalServerError creates a HTTP 500 Internal Server Error response.
func JSON ¶ added in v1.5.0
func JSON(data interface{}) internal.HttpResponse
JSON marshals the given data and sends it to the requester.
func LengthRequired ¶ added in v1.2.0
func LengthRequired(msg string) internal.HttpResponse
LengthRequired creates a HTTP 411 Length Required response.
func LoopDetected ¶ added in v1.2.0
func LoopDetected(msg string) internal.HttpResponse
LoopDetected creates a HTTP 508 Loop Detected response.
func MethodNotAllowed ¶ added in v1.2.0
func MethodNotAllowed(msg string) internal.HttpResponse
MethodNotAllowed creates a HTTP 405 Method Not Allowed response.
func NetworkAuthenticationRequired ¶ added in v1.2.0
func NetworkAuthenticationRequired(msg string) internal.HttpResponse
NetworkAuthenticationRequired creates a HTTP 511 Network Authentication Required response.
func NoContent ¶ added in v1.2.0
func NoContent(ignored ...string) internal.HttpResponse
NoContent creates a HTTP 204 No Content response. The param ignored exists to provide backwards compatibility with an old bug that accepted a message.
func NotAcceptable ¶ added in v1.2.0
func NotAcceptable(msg string) internal.HttpResponse
NotAcceptable creates a HTTP 406 Not Acceptable response.
func NotExtended ¶ added in v1.2.0
func NotExtended(msg string) internal.HttpResponse
NotExtended creates a HTTP 510 Not Extended response.
func NotFound ¶
func NotFound(msg string) internal.HttpResponse
NotFound creates a HTTP 404 Not Found response.
func NotImplemented ¶ added in v1.2.0
func NotImplemented(msg string) internal.HttpResponse
NotImplemented creates a HTTP 501 Not Implemented response.
func NotModified ¶ added in v1.2.0
func NotModified(msg string) internal.HttpResponse
NotModified creates a HTTP 304 Not Modified response.
func OverrideResponseCode ¶
func OverrideResponseCode(hr internal.HttpResponse, code int) internal.HttpResponse
OverrideResponseCode wraps a response to override the status code with the one given to this function. Note that this replaces the original ResponseWriter with an internal one, possibly not implementing interfaces like Flusher.
func PayloadTooLarge ¶ added in v1.2.0
func PayloadTooLarge(msg string) internal.HttpResponse
PayloadTooLarge creates a HTTP 413 Payload Too Large response.
func PreconditionFailed ¶ added in v1.2.0
func PreconditionFailed(msg string) internal.HttpResponse
PreconditionFailed creates a HTTP 412 Precondition Failed response.
func PreconditionRequired ¶ added in v1.2.0
func PreconditionRequired(msg string) internal.HttpResponse
PreconditionRequired creates a HTTP 428 Precondition Required response.
func Printf ¶
func Printf(format string, v ...interface{}) internal.HttpResponse
Printf creates a response that sends a formatted string back to the client.
func RangeNotSatisfiable ¶ added in v1.2.0
func RangeNotSatisfiable(msg string) internal.HttpResponse
RangeNotSatisfiable creates a HTTP 416 Range Not Satisfiable response.
func Reader ¶
func Reader(r io.Reader) internal.HttpResponse
Reader creates a response that copies everything from the reader to the client. If the reader is also an io.Closer, r will be closed. If the reader has a method Len() int, it will be sent as the Content-Length if that header isn't set yet.
func Redirect ¶
func Redirect(code int, url string) internal.HttpResponse
Redirect creates a response that redirects to another URL.
func RenderTemplate ¶
func RenderTemplate(tpl Template, data interface{}) internal.HttpResponse
RenderTemplate creates a response that will render the given template.
func RequestHeaderFieldsTooLarge ¶ added in v1.2.0
func RequestHeaderFieldsTooLarge(msg string) internal.HttpResponse
RequestHeaderFieldsTooLarge creates a HTTP 431 Request Header Fields Too Large response.
func RequestTimeout ¶ added in v1.2.0
func RequestTimeout(msg string) internal.HttpResponse
RequestTimeout creates a HTTP 408 Request Timeout response.
func ResetContent ¶ added in v1.2.0
func ResetContent(msg string) internal.HttpResponse
ResetContent creates a HTTP 205 Reset Content response.
func ServeContent ¶ added in v1.2.0
func ServeContent(name string, modtime time.Time, content io.ReadSeeker) internal.HttpResponse
ServeContent uses http.ServeContent() to serve content.
func ServeFile ¶ added in v1.2.0
func ServeFile(name string) internal.HttpResponse
ServeFile uses http.ServeFile() to serve a file.
func ServeJSON ¶ added in v1.4.0
func ServeJSON(data interface{}) internal.HttpResponse
ServeJSON marshals the given data and sends it to the requester. Deprecated: Use JSON() instead.
func ServiceUnavailable ¶ added in v1.2.0
func ServiceUnavailable(msg string) internal.HttpResponse
ServiceUnavailable creates a HTTP 503 Service Unavailable response.
func String ¶
func String(data string) internal.HttpResponse
String creates a response that sends a string back to the client.
func TooEarly ¶ added in v1.2.0
func TooEarly(msg string) internal.HttpResponse
TooEarly creates a HTTP 425 Too Early response.
func TooManyRequests ¶ added in v1.2.0
func TooManyRequests(msg string) internal.HttpResponse
TooManyRequests creates a HTTP 429 Too Many Requests response.
func URITooLong ¶ added in v1.2.0
func URITooLong(msg string) internal.HttpResponse
URITooLong creates a HTTP 414 URI Too Long response.
func UnavailableForLegalReasons ¶ added in v1.2.0
func UnavailableForLegalReasons(msg string) internal.HttpResponse
UnavailableForLegalReasons creates a HTTP 451 Unavailable For Legal Reasons response.
func UnprocessableEntity ¶ added in v1.2.0
func UnprocessableEntity(msg string) internal.HttpResponse
UnprocessableEntity creates a HTTP 422 Unprocessable Entity response.
func UnsupportedMediaType ¶ added in v1.2.0
func UnsupportedMediaType(msg string) internal.HttpResponse
UnsupportedMediaType creates a HTTP 415 Unsupported Media Type response.
func UpgradeRequired ¶ added in v1.2.0
func UpgradeRequired(msg string) internal.HttpResponse
UpgradeRequired creates a HTTP 426 Upgrade Required response.
func VariantAlsoNegotiates ¶ added in v1.2.0
func VariantAlsoNegotiates(msg string) internal.HttpResponse
VariantAlsoNegotiates creates a HTTP 506 Variant Also Negotiates response.
func WithHeader ¶
func WithHeader(hr internal.HttpResponse, header, value string) internal.HttpResponse
WithHeader wraps a response and adds an additional header to be set.
func WithHeaders ¶
func WithHeaders(hr internal.HttpResponse, headers http.Header) internal.HttpResponse
WithHeaders wraps a response and adds additional headers to be set.