http

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 17 Imported by: 0 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

Overview

readyz.go - the /readyz rollout gate (docs/SPEC.md "Readiness vs liveness"): 200 iff the metadata backend's readiness predicate passes, 503 otherwise, with the mount counts as JSON in both directions so a stalled rollout is diagnosable with curl. /healthz stays pure liveness and never gates on storage.

Package http serves the apex landing + the paste read surface.

The router accepts both URL shapes at once, subdomain (`<slug>.apex`) and path (`apex/p/<slug>`), so the serving side is independent of which URL the SSH server emits after upload.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlobReader

type BlobReader interface {
	Read(ctx context.Context, slug, sha string) (io.ReadCloser, int64, error)
}

BlobReader is the read side of the per-record blob seam. It offers ONLY a streaming read: no serving path may allocate per payload, so the seam does not expose a way to (docs/SPEC.md "Reads are constant-memory too"). It takes the record's slug plus its content sha: the standalone backend keys by sha alone and ignores the slug, the transactional shale backend routes on it. service.BlobUnit satisfies this.

type PasteReader

type PasteReader interface {
	Get(domain.Slug) (domain.Paste, error)
}

PasteReader is the read side of the paste repo, narrowed to what serving needs.

type ReadinessProber added in v0.71.0

type ReadinessProber interface {
	// Ready reports whether this replica should receive traffic and a rollout
	// may proceed past it.
	Ready() bool
	// ReadinessStats returns the counts behind the verdict, echoed in the
	// /readyz body for probe-side diagnosis.
	ReadinessStats() ReadinessStats
}

ReadinessProber is the narrow port /readyz gates on. The composition root wires the shale backend's mount-floor predicate (mounted >= ceil(fraction * desired)) here; backends with no mount concept leave it nil, which means the process being up IS ready since their open failures already fail startup.

type ReadinessStats added in v0.71.0

type ReadinessStats struct {
	// Desired is the number of storage-unit positions this pod owns.
	Desired int `json:"desired"`
	// Mounted is the number of desired positions currently mounted.
	Mounted int `json:"mounted"`
	// Pending positions are in flight or failing.
	Pending int `json:"pending"`
	// FailedOpen is the subset of pending whose last open attempt errored.
	FailedOpen int `json:"failedOpen"`
	// LastAcquireError is one representative open error; omitted when none.
	LastAcquireError string `json:"lastAcquireError,omitempty"`
}

ReadinessStats mirrors the metadata backend's mount counters in the wire shape /readyz emits. All zero on backends with no mount concept.

type RoomRelay added in v0.44.0

type RoomRelay interface {
	// Admit reserves a connection slot under the per-room / per-app /
	// total-rooms caps, returning relay.ErrRoomFull / ErrAppFull /
	// ErrTooManyRooms for the HTTP layer to map to a status. Called BEFORE
	// the websocket handshake.
	Admit(key relay.RoomKey) (*relay.Hub, uint64, error)
	// Serve runs the accepted connection's lifecycle (snapshot, stream,
	// heartbeat) and blocks until it ends.
	Serve(ctx context.Context, key relay.RoomKey, id uint64, ws *websocket.Conn)
	// Release frees a slot reserved by Admit but never handed to Serve.
	Release(key relay.RoomKey, id uint64)
	// CommitAndMirror runs a durable write's KV commit with no relay lock
	// held, so a slow commit never stalls the room, then broadcasts the live
	// mirror locally and publishes it to the peer pods. The commit callback
	// must build the mirror frame AFTER the write so it carries the per-room
	// sequence the commit assigned, which is what orders and de-duplicates it
	// at every subscriber.
	CommitAndMirror(key relay.RoomKey, commit func() (relay.Frame, error)) error
}

RoomRelay is the relay surface the HTTP layer needs to stand up a WebSocket connection for a room. internal/relay.Relay satisfies it. Optional: when nil, the /ws path 404s.

type RoomService added in v0.44.0

type RoomService interface {
	Create(appSlug domain.Slug, subnet string) (domain.Room, error)
	Get(appSlug domain.Slug, id domain.RoomID, key string) ([]byte, error)
	// Scan returns the namespace stamped with the exact per-room sequence its
	// state reflects: the relay's late-join snapshot fence.
	Scan(appSlug domain.Slug, id domain.RoomID) (domain.RoomKV, error)
	// Put / Delete return the mutation's assigned per-room sequence, which the
	// handlers stamp onto the live mirror frame (SPEC.md "The wire format: seq
	// on every durable frame").
	Put(appSlug domain.Slug, id domain.RoomID, key string, val []byte) (uint64, error)
	Delete(appSlug domain.Slug, id domain.RoomID, key string) (uint64, error)
}

RoomService is the application-service surface the HTTP layer needs for the /api/rooms endpoints. internal/service.Rooms satisfies it. Optional: when nil the /api/rooms prefix is not served.

type Server

type Server struct {
	Pastes      PasteReader
	Sites       SiteReader  // optional; nil disables static-site serving
	Rooms       RoomService // optional; nil disables the /api/rooms surface
	Relay       RoomRelay   // optional; nil disables the /api/rooms/<uuid>/ws relay
	Blobs       BlobReader
	LandingHTML []byte // optional; apex landing page bytes embedded at build
	ApexDomain  string // e.g. "hostthis.dev"; used to peel slug subdomains
	// Color labels the replica in blue/green deploys, echoed in the
	// X-Backend-Color header on /healthz. Empty for single-replica deploys.
	Color string
	// Readiness gates /readyz (docs/SPEC.md "Readiness vs liveness") with the
	// metadata backend's readiness predicate. Optional; nil means always
	// ready, for backends with no mount concept whose open failures already
	// fail startup.
	Readiness ReadinessProber
	Now       func() time.Time
	// Logf, when set, receives one warn line per 5xx served by the paste/site
	// read path (docs/SPEC.md "5xx observability on the read surface"): slug +
	// underlying error, so a read 500 is attributable from the logs while the
	// response body stays a generic "internal error". Nil disables.
	Logf func(format string, args ...any)
}

Server bundles the dependencies.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the mux the caller binds with http.ListenAndServe.

type SiteReader added in v0.44.0

type SiteReader interface {
	Get(domain.Slug) (domain.Site, error)
}

SiteReader is the read side for static sites. Optional: nil disables site serving, so a slug then resolves only as a paste. internal/storage.SiteRepo satisfies it.

Jump to

Keyboard shortcuts

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