Documentation
¶
Index ¶
- Constants
- func Cors(w http.ResponseWriter, origin string, methods ...string) error
- func Empty(w http.ResponseWriter, code int, tuples ...string) error
- func Error(w http.ResponseWriter, code int, reason ...string) error
- func ErrorWith(w http.ResponseWriter, code int, v any, reason ...string) error
- func JSON(w http.ResponseWriter, v interface{}, code int, indent uint, tuples ...string) error
- func Text(w http.ResponseWriter, v string, code int, tuples ...string) error
- type ErrorResponse
Constants ¶
View Source
const ( ContentTypeKey = "Content-Type" ContentLengthKey = "Content-Length" ContentTypeJSON = "application/json" ContentTypeText = "text/plain" )
Variables ¶
This section is empty.
Functions ¶
func Cors ¶ added in v1.4.11
func Cors(w http.ResponseWriter, origin string, methods ...string) error
Cors is a utility function to set the CORS headers on a pre-flight request. Setting origin to an empty string or not including methods will allow any origin and any method
func Empty ¶
func Empty(w http.ResponseWriter, code int, tuples ...string) error
Empty is a utility function to serve an empty response. Additional header tuples can be provided as a series of key-value pairs
func Error ¶
func Error(w http.ResponseWriter, code int, reason ...string) error
Error is a utility function to serve a JSON error notice
func ErrorWith ¶ added in v1.4.11
ErrorWith is a utility function to serve a JSON error notice with additional details
Types ¶
type ErrorResponse ¶
type ErrorResponse struct { Code int `json:"code"` Reason string `json:"reason,omitempty"` Detail any `json:"detail,omitempty"` }
ErrorResponse is a generic error response which is served as JSON using the ServeError method
Click to show internal directories.
Click to hide internal directories.