httputil

package
v0.45.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error

func Error(statusCode int, err error) error

Error creates a new HTTP error with a status code from an existing error.

func Errorf

func Errorf(statusCode int, format string, args ...interface{}) error

Errorf creates a new HTTP error with a status code and formatted message message.

func WriteError

func WriteError(w http.ResponseWriter, err error)

WriteError writes an error to the response as a JSON object. If the error is an instance of Error, the status code will be set to the error's code. Otherwise, it will return a 400 status code.

Types

type HTTPError

type HTTPError struct {
	StatusCode int
	Err        error
}

HTTPError represents an error with a HTTP status code.

func (HTTPError) Error

func (e HTTPError) Error() string

func (HTTPError) Unwrap

func (e HTTPError) Unwrap() error

type Handler

type Handler func(http.ResponseWriter, *http.Request) error

Handler is similar to http.HandlerFunc with simple error handling built in. If an error is returned, it will be written to the response as a JSON object (using WriteError).

func (Handler) ServeHTTP

func (fn Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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