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
- type TextStream
Constants ¶
const ( ContentTypeKey = "Content-Type" ContentLengthKey = "Content-Length" ContentTypeJSON = "application/json" ContentTypeText = "text/plain" ContentTypeTextStream = "text/event-stream" )
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
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