Documentation
¶
Index ¶
- func CloseWs(ws *websocket.Conn, message string)
- func DecodeStreamParams(params jsontext.Value, value any) error
- func PingWs(ctx context.Context, ws *websocket.Conn) error
- func QueryDefault(r *http.Request, key, fallback string) string
- func SaveFiles(r *http.Request, path string, maxMemory int64, perm os.FileMode) error
- func SaveFilesRoot(r *http.Request, root *os.Root, path string, maxMemory int64, perm os.FileMode) error
- func SaveToTarFile(r *http.Request, path string, maxMemory int64) (err error)
- func Send(w http.ResponseWriter, r *http.Request, v any)
- func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)
- func UploadName(file *multipart.FileHeader) (string, error)
- func WaitPoll(ctx context.Context, delay time.Duration) bool
- func WriteWsJSON(ctx context.Context, ws *websocket.Conn, value any) error
- type Snapshot
- type SnapshotFunc
- type SnapshotSession
- type StreamCall
- type StreamRegistry
- type StreamSession
- type StreamTopic
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeStreamParams ¶
DecodeStreamParams decodes parameters using the exact JSON field names. Empty or null parameters leave value unchanged.
func SaveFilesRoot ¶
func SaveFilesRoot(r *http.Request, root *os.Root, path string, maxMemory int64, perm os.FileMode) error
SaveFilesRoot confines all filesystem operations, including symlink resolution, to root. The caller owns root.
func SaveToTarFile ¶
SaveToTarFile writes the multipart files to an uncompressed tar archive.
func Send ¶
func Send(w http.ResponseWriter, r *http.Request, v any)
Send encodes a response as JSON or YAML according to the Accept header.
func UploadName ¶
func UploadName(file *multipart.FileHeader) (string, error)
UploadName preserves directory uploads without accepting paths outside the root.
Types ¶
type Snapshot ¶
Snapshot is one reading of a query: the value plus the code and error that describe it.
type SnapshotFunc ¶
SnapshotFunc reads the current state. It must return fresh data, since the previous reading is retained to detect changes.
type SnapshotSession ¶
type SnapshotSession[T any] struct { Query SnapshotFunc[T] Interval time.Duration Frame func(Snapshot[T]) (api.StreamFrame, bool) Done func(Snapshot[T]) bool // contains filtered or unexported fields }
SnapshotSession polls a query and emits a frame only when the reading changes. Frame decides whether a change is worth sending, Done decides whether the subscription is complete after that reading.
func (*SnapshotSession[T]) Close ¶
func (s *SnapshotSession[T]) Close()
Close is a no-op: a polling session holds nothing that outlives the subscription context the transport cancels for it.
func (*SnapshotSession[T]) Next ¶
func (s *SnapshotSession[T]) Next(ctx context.Context) (api.StreamFrame, error)
type StreamCall ¶
StreamCall answers a request that is not a subscription.
type StreamRegistry ¶
type StreamRegistry struct {
// contains filtered or unexported fields
}
StreamRegistry is the routing table of the multiplexed WebSocket: topics are long-lived subscriptions, methods are one-shot calls.
func NewStreamRegistry ¶
func NewStreamRegistry() *StreamRegistry
func (*StreamRegistry) Method ¶
func (g *StreamRegistry) Method(name string, call StreamCall)
Method registers a one-shot method.
func (*StreamRegistry) Serve ¶
func (g *StreamRegistry) Serve(w http.ResponseWriter, r *http.Request)
Serve upgrades the request and multiplexes every subscription and call of the connection over that single socket. All writes are owned by one goroutine, so frames from different sessions cannot interleave.
func (*StreamRegistry) Topic ¶
func (g *StreamRegistry) Topic(name string, topic StreamTopic)
Topic registers a subscription topic.
type StreamSession ¶
type StreamSession interface {
Next(ctx context.Context) (api.StreamFrame, error)
Close()
}
StreamSession produces the frames of one subscription. Next blocks until a frame is ready and returns io.EOF once the subscription is complete. Close may run concurrently with Next and must not block.
type StreamTopic ¶
type StreamTopic func(params jsontext.Value) (StreamSession, error)
StreamTopic opens a session for the parameters a client subscribed with.