httpresponse

package
v1.4.12 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0 Imports: 4 Imported by: 4

Documentation

Index

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

func ErrorWith(w http.ResponseWriter, code int, v any, reason ...string) error

ErrorWith is a utility function to serve a JSON error notice with additional details

func JSON

func JSON(w http.ResponseWriter, v interface{}, code int, indent uint, tuples ...string) error

JSON is a utility function to serve an arbitary object as JSON. Setting the indent value to a non-zero value will indent the JSON. Additional header tuples can be provided as a series of key-value pairs

func Text

func Text(w http.ResponseWriter, v string, code int, tuples ...string) error

Text is a utility function to serve plaintext. Additional header tuples can be provided as a series of key-value pairs

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

Jump to

Keyboard shortcuts

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