Documentation
¶
Overview ¶
Package server is grelot's HTTP API: the routes of every client verb and hook, the standing and in-turn waits, and the in-memory state behind them (presence, open turns, push state). It does not build on Windows, where its store does not run.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Token string
PathRoot string
StorePath string
// ProvidersDir is the folder of the provider files whose http doors
// the server pushes through.
ProvidersDir string
// MaxBytes is the store's ceiling on the bytes in use.
MaxBytes int64
ThreadTTL time.Duration
DormantTTL time.Duration
ReservationMaxTTL time.Duration
}
Config is the server's configuration, read from the environment once at startup.
func LoadConfig ¶
LoadConfig reads the configuration from the environment. Its error names the key to fix and never a secret's value.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub wakes the waits of each identity. Woke, the store's commit notice, closes the channel every wait of those identities holds and replaces it.
type Options ¶
type Options struct {
Store *store.Store
Logger *slog.Logger
Now func() time.Time
// Push defaults to host push through the doors of the providers folder,
// started here and stopped by Release, or to none when it has none.
Push Pusher
// Hub must be the one whose Woke the store's Options.Woke calls; nil
// gives a hub no commit reaches, whose waits wake only at their timeout.
Hub *Hub
// Providers is the providers folder; nil reads Config.ProvidersDir.
Providers fs.FS
// Metrics is the /metrics page the store records into too; nil gives
// the server a page of its own.
Metrics *obs.Metrics
Version string
Config Config
}
Options are what New needs.
type Pusher ¶
type Pusher interface {
// State is id's push state now.
State(id uint64) pushState
// contains filtered or unexported methods
}
Pusher is how the server reaches an identity's host push. Only pushOK counts as working: an identity in any other state is woken by its standing waits, as one with no door is. An implementation calls Hub.Woke for an identity whose state leaves pushOK, or a standing wait already holding sends its due nudge only at its next wake.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the API over one open store.
func (*Server) Beat ¶
Beat records a sweeper pass that committed, which Healthy reads, and forgets the in-memory state of every identity no longer live.
func (*Server) HTTPServer ¶
HTTPServer is the http.Server for Handler. It sets no write timeout, so a held wait can answer at maxWait.
func (*Server) Handler ¶
Handler is the whole API: /healthz and /metrics with no headers, and every /v1 route behind the bearer and the version check.
func (*Server) Healthy ¶
Healthy is the /healthz check: false before the first committed sweeper pass and once the last is older than healthyFor.
func (*Server) Release ¶
func (s *Server) Release()
Release answers every held standing and in-turn wait at once, and every one opened after it, so a graceful stop's drain need not outlast their deadlines. It does not wait for them: http.Server.Shutdown does. It stops host push and waits for it, cancelling a send in flight.