Documentation
¶
Overview ¶
Package server provides the public Starmap HTTP server composition.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Host and Port form the informational HTTP server address. Serve uses the
// caller-provided listener.
Host string
Port int
// PathPrefix is the root for versioned API routes.
PathPrefix string
CORSEnabled bool
CORSOrigins []string
// AuthEnabled controls API-key middleware. AuthHeader names the request
// header carrying the key.
AuthEnabled bool
AuthHeader string
// RateLimit is the per-IP requests-per-minute limit. Zero disables it.
RateLimit int
// CacheTTL bounds derived response-cache entries.
CacheTTL time.Duration
// ReadTimeout, WriteTimeout, and IdleTimeout configure net/http. Zero
// delegates the corresponding timeout policy to the caller/network.
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout time.Duration
// SSEHeartbeatInterval controls flushed comment heartbeats on publication
// streams. SSEWriteTimeout bounds each event or heartbeat write and flush.
SSEHeartbeatInterval time.Duration
SSEWriteTimeout time.Duration
// ShutdownGracePeriod bounds internal service cleanup after HTTP draining.
ShutdownGracePeriod time.Duration
// MetricsEnabled exposes the process metrics endpoint.
MetricsEnabled bool
}
Config configures an embeddable Starmap HTTP server.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns production-oriented server defaults.
type ConnectedRuntime ¶ added in v0.16.0
type ConnectedRuntime interface {
// Status reports the observable runtime state without a source read.
Status() status.Status
// Close ends the runtime background work under its own bounded join.
Close() error
}
ConnectedRuntime is the whole contract the server needs from a connected catalog runtime. The server reports the status and joins the shutdown, and it never reads a catalog source itself.
The narrow contract keeps the attested source machinery out of the public server dependency closure. A consumer that embeds the server around an offline client therefore pays for none of it. *runtime.Runtime in github.com/agentstation/starmap/runtime satisfies this contract.
type Health ¶
type Health struct {
State State `json:"state"`
ActiveGenerationID string `json:"active_generation_id,omitempty"`
CatalogGeneratedAt time.Time `json:"catalog_generated_at"`
CatalogAgeSeconds int64 `json:"catalog_age_seconds"`
Publication PublicationHealth `json:"publication"`
Stream StreamHealth `json:"stream"`
}
Health is an immutable snapshot of publisher catalog, callback, and stream delivery health. Only the active generation timestamp determines catalog generation timestamp. Heartbeat activity cannot refresh it.
type Option ¶
type Option func(*options) error
Option configures a Server dependency.
func WithLogger ¶
WithLogger configures server diagnostics. The default logger discards output.
func WithRuntime ¶ added in v0.16.0
func WithRuntime(connected ConnectedRuntime) Option
WithRuntime joins the server to one connected runtime. Readiness then reports the runtime status, and Shutdown joins the runtime shutdown.
func WithSyncer ¶
WithSyncer enables explicit source acquisition through the update endpoint.
type PublicationHealth ¶
type PublicationHealth struct {
Completed uint64 `json:"completed"`
Failures uint64 `json:"failures"`
Panics uint64 `json:"panics"`
Coalesced uint64 `json:"coalesced"`
LastLatency time.Duration `json:"last_latency"`
MaxLatency time.Duration `json:"max_latency"`
}
PublicationHealth reports post-commit callback delivery, including every pending generation coalesced by the bounded callback dispatcher.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves one Starmap client's immutable catalog over HTTP.
Construction starts no listener or background goroutine. Serve starts the server-owned services and blocks until the listener fails or Shutdown drains the HTTP server.
func (*Server) Handler ¶
Handler returns the configured HTTP handler. Call Start before serving this handler through a caller-owned http.Server. The caller must drain that http.Server before calling Shutdown to stop Starmap's background services.
func (*Server) Serve ¶
Serve starts server-owned services and serves listener until Shutdown or a listener failure. A normal Shutdown returns nil.
type StreamHealth ¶
type StreamHealth struct {
State StreamState `json:"state"`
Clients int `json:"clients"`
LastHeartbeatAt time.Time `json:"last_heartbeat_at"`
LastEventAt time.Time `json:"last_event_at"`
LastGenerationID string `json:"last_generation_id,omitempty"`
LastSequence uint64 `json:"last_sequence"`
LastErrorKind string `json:"last_error_kind,omitempty"`
LastErrorAt time.Time `json:"last_error_at"`
Published uint64 `json:"published"`
Sent uint64 `json:"sent"`
Heartbeats uint64 `json:"heartbeats"`
Disconnected uint64 `json:"disconnected"`
BackpressureTerminated uint64 `json:"backpressure_terminated"`
Failed uint64 `json:"failed"`
}
StreamHealth reports SSE liveness and delivery. BackpressureTerminated and Failed make every forced connection recovery observable.
type StreamState ¶
type StreamState string
StreamState is the server-side SSE publication stream state.
const ( // StreamStateIdle means the broadcaster accepts streams but has no clients. StreamStateIdle StreamState = "idle" // StreamStateStreaming means the broadcaster has active clients. StreamStateStreaming StreamState = "streaming" // StreamStateStopped means the broadcaster rejects new streams. StreamStateStopped StreamState = "stopped" )