response

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: 0BSD Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStreamClosed = errors.New("stream closed")

ErrStreamClosed is returned when a write is attempted on a closed stream.

Functions

func JSON

func JSON(w http.ResponseWriter, data any)

func PrepareTemplate added in v0.0.10

func PrepareTemplate(templateFiles embed.FS) *template.Template

Removes the top-level folder, as well as file extensions. Panics on errors.

//go:embed templates
var templateFiles embed.FS
var tmpls = response.PrepareTemplate(templateFiles)
response.Template(tmpls, w, "template name", data)

func Template added in v0.0.10

func Template(tmpl *template.Template, w http.ResponseWriter, templateName string, data any)

func WebSocket added in v0.0.8

func WebSocket(handler func(*WebSocketConnection)) http.Handler

Types

type StreamResponse added in v0.0.9

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

func Stream

Turns a long-running operation into a server-sent event stream

func (*StreamResponse) Closed added in v0.0.9

func (s *StreamResponse) Closed() bool

func (*StreamResponse) Send added in v0.0.9

func (s *StreamResponse) Send(message string) error

func (*StreamResponse) SendEvent added in v0.0.9

func (s *StreamResponse) SendEvent(eventName, message string) error

type WebSocketConnection added in v0.0.8

type WebSocketConnection struct {
	// MaxMessageSize caps the total size of a reassembled (possibly fragmented)
	// message. Defaults to 16 MB
	MaxMessageSize int64
	// contains filtered or unexported fields
}

WebSocketConnection is a single upgraded WebSocket connection

func (*WebSocketConnection) Close added in v0.0.8

func (ws *WebSocketConnection) Close() error

func (*WebSocketConnection) Read added in v0.0.8

func (ws *WebSocketConnection) Read() (string, error)

Must be called from a single goroutine only

func (*WebSocketConnection) ReadBytes added in v0.0.8

func (ws *WebSocketConnection) ReadBytes() ([]byte, error)

Must be called from a single goroutine only

func (*WebSocketConnection) ReadMessage added in v0.0.8

func (ws *WebSocketConnection) ReadMessage() (WebSocketMessage, error)

Must be called from a single goroutine only

func (*WebSocketConnection) Send added in v0.0.8

func (ws *WebSocketConnection) Send(msg string) error

Safe for concurrent use

func (*WebSocketConnection) SendBytes added in v0.0.8

func (ws *WebSocketConnection) SendBytes(data []byte) error

Safe for concurrent use

func (*WebSocketConnection) WritePing added in v0.0.8

func (ws *WebSocketConnection) WritePing(payload []byte) error

WritePing sends a ping control frame with an optional payload (<=125 bytes).

func (*WebSocketConnection) WritePong added in v0.0.8

func (ws *WebSocketConnection) WritePong(payload []byte) error

WritePong sends a pong control frame, normally in response to a ping.

type WebSocketMessage added in v0.0.8

type WebSocketMessage struct {
	Payload  []byte
	IsBinary bool
}

Jump to

Keyboard shortcuts

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