Documentation ¶
Overview ¶
Package web contains helpers for web handlers
Index ¶
- func ErrorText(code int) string
- func HandleError(rw http.ResponseWriter, req *http.Request, err error)
- func WithErrorHandler(ctx context.Context, h ErrorHandlerFunc) context.Context
- type Error
- type ErrorHandlerFunc
- type HTTPError
- func (err *HTTPError) AddHeader(key, value string)
- func (err *HTTPError) DeleteHeader(key string)
- func (err *HTTPError) Error() string
- func (err *HTTPError) Header() http.Header
- func (err *HTTPError) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (err *HTTPError) SetHeader(key, value string)
- func (err *HTTPError) Status() int
- func (err *HTTPError) Unwrap() error
- type Handler
- type HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleError ¶ added in v0.4.3
func HandleError(rw http.ResponseWriter, req *http.Request, err error)
HandleError attempts to call the ErrorHandler set for the content, otherwise it serves the error directly using its own ServeHTTP if defined or HTTPError if not.
func WithErrorHandler ¶
func WithErrorHandler(ctx context.Context, h ErrorHandlerFunc) context.Context
WithErrorHandler attaches an ErrorHandler function to a context for later retrieval
Types ¶
type ErrorHandlerFunc ¶
type ErrorHandlerFunc func(http.ResponseWriter, *http.Request, error)
ErrorHandlerFunc is the signature of a function used as ErrorHandler
func ErrorHandler ¶
func ErrorHandler(ctx context.Context) (ErrorHandlerFunc, bool)
ErrorHandler attempts to pull an ErrorHandler from the context.Context
type HTTPError ¶
HTTPError extends core.WrappedError with HTTP Status Code
func NewHTTPError ¶
NewHTTPError creates a new HTTPError with a given StatusCode and optional cause and annotation
func NewHTTPErrorf ¶
NewHTTPErrorf creates a new HTTPError with a given StatusCode and optional cause and formatted annotation
func (*HTTPError) DeleteHeader ¶
DeleteHeader removes a header key from the HTTPError if present
func (*HTTPError) Header ¶
Header returns a http.Header attached to this error for custom fields
func (*HTTPError) ServeHTTP ¶
func (err *HTTPError) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP is a very primitive handler that will try to pass the error to a [middleware.ErrorHandlerFunc] provided via the request's context.Context
type Handler ¶ added in v0.4.3
type Handler interface {
TryServeHTTP(http.ResponseWriter, *http.Request) error
}
A Handler is like http.Handler but doesn't render or handle errors by itself.
type HandlerFunc ¶ added in v0.4.3
type HandlerFunc func(http.ResponseWriter, *http.Request) error
HandlerFunc is a function that implements http.Handler and our Handler. HandleError will be called when using the http.Handler interface and the function returns an error.
func (HandlerFunc) ServeHTTP ¶ added in v0.4.3
func (fn HandlerFunc) ServeHTTP(rw http.ResponseWriter, req *http.Request)
func (HandlerFunc) TryServeHTTP ¶ added in v0.4.3
func (fn HandlerFunc) TryServeHTTP(rw http.ResponseWriter, req *http.Request) error
TryServeHTTP implements the Handler interface.
Directories ¶
Path | Synopsis |
---|---|
Package assets assists serving embedded assets via HTTP
|
Package assets assists serving embedded assets via HTTP |
Package html facilitates use of html/template.Template
|
Package html facilitates use of html/template.Template |
Package qlist provides a processor for HTTP Quality Lists
|
Package qlist provides a processor for HTTP Quality Lists |
Package respond assists handlers to produce reponses
|
Package respond assists handlers to produce reponses |