httpx

package
v0.0.0-...-54d5358 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package httpx is a convenience wrapper around the http.ServeMux type that allows us to return errors from our handlers. see https://blog.questionable.services/article/http-handler-error-handling-revisited/ for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(code int, err error) error

Error is a convenience function for returning an error with an associated HTTP status code.

func HandlerFunc

func HandlerFunc[E env](envFn func(r *http.Request) E, fn func(E, http.ResponseWriter, *http.Request) error) http.HandlerFunc

HandlerFunc adapts a function that returns an error to an http.HandlerFunc.

func Params

func Params(r *http.Request, v interface{}) error

Params decodes the request parameters of a POST request into the given struct based on the Content-Type header. It returns an error if the Content-Type is not supported.

func Redirect

func Redirect(w http.ResponseWriter, uri string) error

Redirect returns a 302 redirect to the specified URI.

Types

type StatusError

type StatusError struct {
	Code int
	Err  error
}

StatusError represents an error with an associated HTTP status code.

func (*StatusError) Error

func (se *StatusError) Error() string

Allows StatusError to satisfy the error interface.

func (*StatusError) Status

func (se *StatusError) Status() int

Returns our HTTP status code.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL