httpresponse

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 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)
	ErrServiceUnavailable = Err(http.StatusServiceUnavailable)
	ErrGatewayError       = Err(http.StatusBadGateway)
)

Variables

This section is empty.

Functions

func Attachment

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

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

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

type Err int

Err turns a HTTP status code into an error

func (Err) Error

func (code Err) Error() string

func (Err) With

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

func (Err) Withf

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

type TextStream

type TextStream struct {
	// contains filtered or unexported fields
}

TextStream implements a stream of text events

func NewTextStream

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

func (s *TextStream) Close() error

Close the text stream to stop sending ping messages

func (*TextStream) Write

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