http

package
v1.8.8 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 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(err error, code int) error

Error returns an error that can be used to write an HTTP response with an error message and a specific status code.

func ErrorStr added in v1.8.8

func ErrorStr(err string, code int) error

ErrorStr is like Error but takes a string message instead of an error.

func SetCacheHeaders

func SetCacheHeaders(w http.ResponseWriter, maxAge time.Duration, timeUntilExpiry time.Duration)

func SetNoCacheHeaders

func SetNoCacheHeaders(w http.ResponseWriter)

func WriteErrorJSON

func WriteErrorJSON(w http.ResponseWriter, err error)

WriteErrorJSON writes an error response in JSON format to the provided http.ResponseWriter. If the error is an *httpError, it uses the code and error message from that error. Otherwise, it defaults to http.StatusInternalServerError, obfuscating the error message in that case.

func WriteResponseJSON

func WriteResponseJSON(w http.ResponseWriter, code int, body any)

Types

type HTTPError added in v1.8.8

type HTTPError struct {
	// contains filtered or unexported fields
}

func (*HTTPError) Code added in v1.8.8

func (e *HTTPError) Code() int

func (*HTTPError) Error added in v1.8.8

func (e *HTTPError) Error() string

Jump to

Keyboard shortcuts

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