Documentation
¶
Index ¶
- Constants
- func Attachment(w http.ResponseWriter, r io.Reader, code int, params map[string]string) error
- func Cors(w http.ResponseWriter, r *http.Request, origin string, methods ...string)
- func Empty(w http.ResponseWriter, code int) error
- func Error(w http.ResponseWriter, err error, detail ...any) error
- func JSON(w http.ResponseWriter, code, indent int, v any) error
- func Write(w http.ResponseWriter, code int, contentType string, ...) error
- type Err
- type TextStream
Constants ¶
const ( ErrBadRequest = Err(http.StatusBadRequest) ErrNotFound = Err(http.StatusNotFound) ErrConflict = Err(http.StatusConflict) ErrNotImplemented = Err(http.StatusNotImplemented) ErrInternalError = Err(http.StatusInternalServerError) ErrNotAuthorized = Err(http.StatusUnauthorized) ErrForbidden = Err(http.StatusForbidden) ErrGatewayError = Err(http.StatusBadGateway) )
Variables ¶
This section is empty.
Functions ¶
func Attachment ¶ added in v1.5.0
Attachment will write out an attachment from a io.Reader
func Empty ¶
func Empty(w http.ResponseWriter, code int) error
Empty is a utility function to serve an empty response
func Error ¶
func Error(w http.ResponseWriter, err error, detail ...any) error
Error writes an error from a HTTP status code, with additional detail
func JSON ¶
func JSON(w http.ResponseWriter, code, indent int, v any) error
JSON will write a JSON response to the writer with a HTTP status code, optionally indenting the JSON by a number of spaces
func Write ¶ added in v1.5.15
func Write(w http.ResponseWriter, code int, contentType string, fn func(w io.Writer) (int, error)) error
Write a custom response to the writer with a HTTP status code. If the custom function is set and returns the number of bytes written (greater than zero), it will be used to write the response body.
Types ¶
type TextStream ¶ added in v1.4.14
type TextStream struct {
// contains filtered or unexported fields
}
TextStream implements a stream of text events
func NewTextStream ¶ added in v1.4.14
func NewTextStream(w http.ResponseWriter, tuples ...string) *TextStream
Create a new text stream with mimetype text/event-stream Additional header tuples can be provided as a series of key-value pairs
func (*TextStream) Close ¶ added in v1.4.14
func (s *TextStream) Close() error
Close the text stream to stop sending ping messages
func (*TextStream) Write ¶ added in v1.4.14
func (s *TextStream) Write(name string, data ...any)
Write a text event to the stream, and one or more optional data objects which are encoded as JSON