Documentation ¶
Overview ¶
Package respond assists handlers to produce reponses
Index ¶
- func Register(ct string, h Renderer) error
- type Registry
- func (reg *Registry) Clone() *Registry
- func (reg *Registry) Get(ct string) (r Renderer, found bool)
- func (reg *Registry) GetParsed(ct string) (qlist.QualityValue, bool)
- func (reg *Registry) Register(ct string, h Renderer) error
- func (reg *Registry) Replace(ct string, h Renderer) (Renderer, error)
- func (reg *Registry) SetIdentity(ct string) error
- func (reg *Registry) Supports(types ...string) *Responder
- type RenderFunc
- type Renderer
- type Responder
- type Response
- func (r *Response) Accepted(rw http.ResponseWriter) *Response
- func (r *Response) AddHeader(key, value string)
- func (r *Response) BadGateway(rw http.ResponseWriter) *Response
- func (r *Response) BadRequest(rw http.ResponseWriter) *Response
- func (r *Response) Code() int
- func (r *Response) Conflict(rw http.ResponseWriter) *Response
- func (r *Response) ContentType() string
- func (r *Response) Created(rw http.ResponseWriter) *Response
- func (r *Response) DeleteHeader(key string)
- func (r *Response) Forbidden(rw http.ResponseWriter) *Response
- func (r *Response) Found(rw http.ResponseWriter, loc string) error
- func (r *Response) GatewayTimeout(rw http.ResponseWriter) *Response
- func (r *Response) Gone(rw http.ResponseWriter) *Response
- func (r *Response) InternalServerError(rw http.ResponseWriter) *Response
- func (r *Response) LengthRequired(rw http.ResponseWriter) *Response
- func (r *Response) MethodNotAllowed(rw http.ResponseWriter) *Response
- func (r *Response) MovedPermanently(rw http.ResponseWriter, loc string) error
- func (r *Response) NoContent(rw http.ResponseWriter)
- func (r *Response) NotAcceptable(rw http.ResponseWriter) *Response
- func (r *Response) NotFound(rw http.ResponseWriter) *Response
- func (r *Response) NotImplemented(rw http.ResponseWriter) *Response
- func (r *Response) OK(rw http.ResponseWriter) *Response
- func (r *Response) PermanentRedirect(rw http.ResponseWriter, loc string) error
- func (r *Response) PreconditionFailed(rw http.ResponseWriter) *Response
- func (r *Response) Render(v any) error
- func (r *Response) RequestEntityTooLarge(rw http.ResponseWriter) *Response
- func (r *Response) SeeOther(rw http.ResponseWriter, loc string) error
- func (r *Response) ServiceUnavailable(rw http.ResponseWriter) *Response
- func (r *Response) SetHeader(key, value string)
- func (r *Response) TemporaryRedirect(rw http.ResponseWriter, loc string) error
- func (r *Response) Unauthorized(rw http.ResponseWriter) *Response
- func (r *Response) UnprocessableEntity(rw http.ResponseWriter) *Response
- func (r *Response) UnsupportedMediaType(rw http.ResponseWriter) *Response
- func (r *Response) WithStatus(code int) *Response
- func (r *Response) WithWriter(rw http.ResponseWriter) *Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
A Registry is a collection of Renderers
func CloneRegistry ¶
func CloneRegistry() *Registry
CloneRegistry creates a new Registry using the global as starting point
func NewRegistry ¶
NewRegistry creates a new Renderers Registry optionally starting with a given set of Renderers
func (*Registry) GetParsed ¶
func (reg *Registry) GetParsed(ct string) (qlist.QualityValue, bool)
GetParsed retrieves the parsed qlist.QualityValue of a given Media Type if the Registry knows it
func (*Registry) Replace ¶
Replace registers or replaces a Renderer on the Registry. Returns the previous Renderer assigned to the specified Content-Type
func (*Registry) SetIdentity ¶
SetIdentity defines the default Content-Type for this Registry. Otherwise it will be the first registered Renderer
type RenderFunc ¶
A RenderFunc writes the v object encoded
type Renderer ¶
Renderer is an object that renders objects with a predetermined encoding
func GetRenderer ¶
GetRenderer retrieves a Renderer from the global Registry, or its Identity.
func NewRenderer ¶
func NewRenderer(ct string, h RenderFunc) Renderer
NewRenderer creates a Renderer implementation using the given content type string and render functions
type Responder ¶
type Responder struct {
// contains filtered or unexported fields
}
A Responder is a narrowed set of supported Media Types
func Supports ¶
Supports creates a new Responder supporting the given media types, using the global Registry
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is the stage to build and send the response for a particular request
func (*Response) Accepted ¶
func (r *Response) Accepted(rw http.ResponseWriter) *Response
Accepted prepares a 202 Accepted Response
func (*Response) BadGateway ¶
func (r *Response) BadGateway(rw http.ResponseWriter) *Response
BadGateway prepares a 502 Bad Gateway Response
func (*Response) BadRequest ¶
func (r *Response) BadRequest(rw http.ResponseWriter) *Response
BadRequest prepares a 400 Bad Request Response
func (*Response) Conflict ¶
func (r *Response) Conflict(rw http.ResponseWriter) *Response
Conflict prepares a 409 Conflict Response
func (*Response) ContentType ¶
ContentType is the preferred Media Type for this Response
func (*Response) Created ¶
func (r *Response) Created(rw http.ResponseWriter) *Response
Created prepares a 201 Created Response
func (*Response) DeleteHeader ¶
DeleteHeader removes a header key from the response
func (*Response) Forbidden ¶
func (r *Response) Forbidden(rw http.ResponseWriter) *Response
Forbidden prepares a 403 Forbidden Response
func (*Response) Found ¶
func (r *Response) Found(rw http.ResponseWriter, loc string) error
Found sends a 302 Found Response
func (*Response) GatewayTimeout ¶
func (r *Response) GatewayTimeout(rw http.ResponseWriter) *Response
GatewayTimeout prepares a 504 Gateway Timeout Response
func (*Response) Gone ¶
func (r *Response) Gone(rw http.ResponseWriter) *Response
Gone prepares a 410 Gone Response
func (*Response) InternalServerError ¶
func (r *Response) InternalServerError(rw http.ResponseWriter) *Response
InternalServerError prepares a 500 Internal Server Error Response
func (*Response) LengthRequired ¶
func (r *Response) LengthRequired(rw http.ResponseWriter) *Response
LengthRequired prepares a 411 Length Required Response
func (*Response) MethodNotAllowed ¶
func (r *Response) MethodNotAllowed(rw http.ResponseWriter) *Response
MethodNotAllowed prepares a 405 Method Not Allowed Response
func (*Response) MovedPermanently ¶
func (r *Response) MovedPermanently(rw http.ResponseWriter, loc string) error
MovedPermanently sends a 301 Moved Permanently Response
func (*Response) NoContent ¶
func (r *Response) NoContent(rw http.ResponseWriter)
NoContent sends a 204 No Content Response. Render isn't used.
func (*Response) NotAcceptable ¶
func (r *Response) NotAcceptable(rw http.ResponseWriter) *Response
NotAcceptable prepares a 406 Not Acceptable Response
func (*Response) NotFound ¶
func (r *Response) NotFound(rw http.ResponseWriter) *Response
NotFound prepares a 404 Not Found Response
func (*Response) NotImplemented ¶
func (r *Response) NotImplemented(rw http.ResponseWriter) *Response
NotImplemented prepares a 501 Not Implemented Response
func (*Response) OK ¶
func (r *Response) OK(rw http.ResponseWriter) *Response
OK prepares a 200 OK Response
func (*Response) PermanentRedirect ¶
func (r *Response) PermanentRedirect(rw http.ResponseWriter, loc string) error
PermanentRedirect sends a 308 Permanent Redirect Response
func (*Response) PreconditionFailed ¶
func (r *Response) PreconditionFailed(rw http.ResponseWriter) *Response
PreconditionFailed prepares a 412 Precondition Failed Response
func (*Response) RequestEntityTooLarge ¶
func (r *Response) RequestEntityTooLarge(rw http.ResponseWriter) *Response
RequestEntityTooLarge prepares a 413 Request Entity Too Large Response
func (*Response) SeeOther ¶
func (r *Response) SeeOther(rw http.ResponseWriter, loc string) error
SeeOther sends a 303 See Other Response
func (*Response) ServiceUnavailable ¶
func (r *Response) ServiceUnavailable(rw http.ResponseWriter) *Response
ServiceUnavailable prepares a 503 Service Unavailable Response
func (*Response) TemporaryRedirect ¶
func (r *Response) TemporaryRedirect(rw http.ResponseWriter, loc string) error
TemporaryRedirect sends a 307 Temporary Redirect Response
func (*Response) Unauthorized ¶
func (r *Response) Unauthorized(rw http.ResponseWriter) *Response
Unauthorized prepares a 401 Unauthorized Response
func (*Response) UnprocessableEntity ¶
func (r *Response) UnprocessableEntity(rw http.ResponseWriter) *Response
UnprocessableEntity prepares a 422 Unprocessable Entity Response
func (*Response) UnsupportedMediaType ¶
func (r *Response) UnsupportedMediaType(rw http.ResponseWriter) *Response
UnsupportedMediaType prepares a 415 Unsupported Media Type Response
func (*Response) WithStatus ¶
WithStatus sets the status code directly, to be used in conjunction with [WithWriter].
func (*Response) WithWriter ¶
func (r *Response) WithWriter(rw http.ResponseWriter) *Response
WithWriter sets the writer directly, to be used in conjunction with [WithStatus].