Documentation ¶
Overview ¶
Package httputil provides utilities for implementing web frontends and APIs with the Go standard library.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSON ¶
func ExpectStatus ¶
ExpectStatus errors if code is not in the allowed list.
func OK ¶
func OK(w http.ResponseWriter)
OK responds with an ok response. Intended for serverless handlers.
Types ¶
type Error ¶
Error is an error with an associated HTTP status code.
func BadRequest ¶
BadRequest builds a 400 error with StatusBadRequest.
func InternalServerError ¶
InternalServerError builds a 500 error.
func MethodNotAllowed ¶
MethodNotAllowed builds a 405 error.
func StatusError ¶
StatusError builds an error for the given status code, with the standard status text.
type ErrorHandler ¶
ErrorHandler wraps a HandlerFunc with an error handling layer.
func (ErrorHandler) ServeHTTP ¶
func (h ErrorHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Handler ¶
type Handler interface {
HandleRequest(w http.ResponseWriter, r *http.Request) error
}
Handler handles a HTTP request and returns a possible error.
func ProxySingleURL ¶
ProxySingleURL is a handler that serves the content at the given URL.
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
HandlerFunc adapts a function to the Handler interface.
func (HandlerFunc) HandleRequest ¶
func (h HandlerFunc) HandleRequest(w http.ResponseWriter, r *http.Request) error
HandleRequest calls h.
type JSONDecoder ¶
type JSONDecoder struct {
MaxRequestSize int64
}
func (*JSONDecoder) DecodeRequest ¶
func (j *JSONDecoder) DecodeRequest(w http.ResponseWriter, r *http.Request, v interface{}) error
type JSONEncoder ¶
type JSONEncoder struct {
Debug bool
}
func (*JSONEncoder) EncodeResponse ¶
func (j *JSONEncoder) EncodeResponse(w http.ResponseWriter, v interface{}) error