httpx

package
v0.0.0-...-2fa33bc Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseWs

func CloseWs(ws *websocket.Conn, message string)

func DecodeStreamParams

func DecodeStreamParams(params jsontext.Value, value any) error

DecodeStreamParams decodes parameters using the exact JSON field names. Empty or null parameters leave value unchanged.

func PingWs

func PingWs(ctx context.Context, ws *websocket.Conn) error

func QueryDefault

func QueryDefault(r *http.Request, key, fallback string) string

func SaveFiles

func SaveFiles(r *http.Request, path string, maxMemory int64, perm os.FileMode) error

SaveFiles creates the destination directory and saves the multipart files in it.

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

func SaveToTarFile(r *http.Request, path string, maxMemory int64) (err error)

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 Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request) (*websocket.Conn, error)

func UploadName

func UploadName(file *multipart.FileHeader) (string, error)

UploadName preserves directory uploads without accepting paths outside the root.

func WaitPoll

func WaitPoll(ctx context.Context, delay time.Duration) bool

WaitPoll sleeps for the poll interval and reports whether the caller should continue.

func WriteWsJSON

func WriteWsJSON(ctx context.Context, ws *websocket.Conn, value any) error

Types

type Snapshot

type Snapshot[T any] struct {
	Code api.Code
	Data T
	Err  error
}

Snapshot is one reading of a query: the value plus the code and error that describe it.

type SnapshotFunc

type SnapshotFunc[T any] func(ctx context.Context) (api.Code, T, error)

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

type StreamCall func(ctx context.Context, params jsontext.Value) (any, error)

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.

Jump to

Keyboard shortcuts

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