httpresponse

package
v1.5.17 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2025 License: Apache-2.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
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

func Attachment(w http.ResponseWriter, r io.Reader, code int, params map[string]string) error

Attachment will write out an attachment from a io.Reader

func Cors added in v1.4.11

func Cors(w http.ResponseWriter, r *http.Request, origin string, methods ...string)

Write the cors headers

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 Err added in v1.5.0

type Err int

Err turns a HTTP status code into an error

func (Err) Error added in v1.5.0

func (code Err) Error() string

func (Err) With added in v1.5.0

func (code Err) With(args ...interface{}) error

func (Err) Withf added in v1.5.0

func (code Err) Withf(format string, args ...interface{}) error

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

Jump to

Keyboard shortcuts

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