server

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 32 Imported by: 0

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

func LoadConfig() (Config, error)

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.

func NewHub

func NewHub() *Hub

NewHub returns a hub no wait holds yet.

func (*Hub) Woke

func (h *Hub) Woke(ids []uint64)

Woke wakes every wait of each of ids. It only closes channels and tells the listener, as store.Options.Woke requires.

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 New

func New(o *Options) *Server

New builds the server. Options.Now defaults to time.Now and must be the store's clock.

func (*Server) Beat

func (s *Server) Beat(ctx context.Context)

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

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

HTTPServer is the http.Server for Handler. It sets no write timeout, so a held wait can answer at maxWait.

func (*Server) Handler

func (s *Server) Handler() http.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

func (s *Server) Healthy() bool

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.

Jump to

Keyboard shortcuts

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