sse

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package sse provides experimental server-sent event helpers for streaming rendered partials.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventName

type EventName string
const (
	EventPatch  EventName = "partial:patch"
	EventSignal EventName = "partial:signal"
	EventError  EventName = "partial:error"
)

func (EventName) String

func (e EventName) String() string

type HeaderKey

type HeaderKey string
const (
	HeaderContentType     HeaderKey = "Content-Type"
	HeaderCacheControl    HeaderKey = "Cache-Control"
	HeaderConnection      HeaderKey = "Connection"
	HeaderXAccelBuffering HeaderKey = "X-Accel-Buffering"
)

func (HeaderKey) String

func (h HeaderKey) String() string

type HeaderValue

type HeaderValue string
const (
	ContentTypeEventStream HeaderValue = "text/event-stream"
	CacheControlNoCache    HeaderValue = "no-cache"
	ConnectionKeepAlive    HeaderValue = "keep-alive"
	XAccelBufferingNo      HeaderValue = "no"
)

func (HeaderValue) String

func (v HeaderValue) String() string

type Patch

type Patch struct {
	Target string        `json:"target"`
	HTML   template.HTML `json:"html"`
}

type Signal

type Signal struct {
	Name  string `json:"name"`
	Value any    `json:"value"`
}

type Writer

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

Writer streams server-sent events to one http.ResponseWriter.

Writer is bound to a single response stream and is not safe for concurrent writes unless the caller serializes access.

func NewWriter

func NewWriter(w http.ResponseWriter) *Writer

func (*Writer) ApplyHeaders

func (s *Writer) ApplyHeaders()

func (*Writer) Comment

func (s *Writer) Comment(comment string) error

func (*Writer) Error

func (s *Writer) Error(err error) error

func (*Writer) Event

func (s *Writer) Event(event EventName, data any) error

func (*Writer) EventID

func (s *Writer) EventID(id string, event EventName, data any) error

func (*Writer) Flush

func (s *Writer) Flush()

func (*Writer) PatchHTML

func (s *Writer) PatchHTML(target string, html template.HTML) error

func (*Writer) PatchPartial

func (s *Writer) PatchPartial(ctx context.Context, r *http.Request, target string, p *partial.Partial) error

func (*Writer) Retry

func (s *Writer) Retry(after time.Duration) error

func (*Writer) Signal

func (s *Writer) Signal(name string, value any) error

func (*Writer) Use

func (s *Writer) Use(stages ...partial.RenderStage) *Writer

Use appends render stages to partials rendered by this writer.

Jump to

Keyboard shortcuts

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