Documentation
¶
Overview ¶
Package server runs the three listeners of C-02.FR-3: ingest (ingestion, Heartbeat, Mattermost callbacks, the Telegram webhook), app (UI and API) and internal (health and metrics). When ingest and app have the same address, one server routes the ingest paths to the ingest handler and every other path to the app handler.
Index ¶
- Constants
- func App(api http.Handler, dist fs.FS, hsts bool) http.Handler
- func Ingest(ingest, heartbeat, callbacks http.Handler) http.Handler
- func Internal(h *Health, metrics http.Handler) http.Handler
- func IsCallbackPath(p string) bool
- func IsHeartbeatPath(p string) bool
- func IsIngestPath(p string) bool
- func Merge(app, ingest http.Handler) http.Handler
- func SPA(dist fs.FS) http.Handler
- type Addresses
- type Handlers
- type Health
- type ListenerError
- type Server
Constants ¶
const ( ListenerApp = "app" ListenerIngest = "ingest" ListenerInternal = "internal" )
The names of the listeners, as log lines and errors call them.
const ContentSecurityPolicy = "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; " +
"connect-src 'self'; font-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; " +
"frame-ancestors 'none'"
ContentSecurityPolicy is the Content Security Policy of every answer of the app listener (C-03.FR-16): everything from the app's own origin, images also as data: URIs, no plugins, no base URI, forms posted only to itself and no framing.
Variables ¶
This section is empty.
Functions ¶
func App ¶
App is the handler of the app listener: every path under /api/ goes to api, which answers unknown API paths with a problem, and every other path to the SPA in dist. Every answer carries the security headers, with Strict-Transport-Security when hsts is set, which it is when MUSTER_PUBLIC_URL is https.
func Ingest ¶
Ingest is the handler of the ingest listener: heartbeat serves the Heartbeat endpoint, callbacks the messenger callbacks, and ingest everything else, ingestion first.
func Internal ¶
Internal is the handler of the internal listener: /health/live, /health/ready and metrics at /metrics (getMetrics).
func IsCallbackPath ¶
IsCallbackPath reports whether p is under the messenger callbacks, /api/v1/callbacks/.
func IsHeartbeatPath ¶
IsHeartbeatPath reports whether p is the Heartbeat endpoint, with or without a token in the path.
func IsIngestPath ¶
IsIngestPath reports whether the ingest handler serves p: ingestion, the Heartbeat, and the Mattermost and Telegram callbacks.
func Merge ¶
Merge routes the ingest paths to ingest and every other path to app, for one port that serves both.
func SPA ¶
SPA serves the single-page application in dist: a file that exists as itself, any other path as index.html, so that the SPA's router handles it. A missing file under assets/ answers 404 instead: a page left open across an upgrade asks for chunks of the old build, and index.html in their place would fail as a script of the wrong type. Without a built index.html it answers 503.
Types ¶
type Addresses ¶
type Addresses struct {
App, Ingest, Internal string
}
Addresses are the listen addresses.
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
Health answers the probes of the internal listener (C-02.FR-4): liveness without checks, readiness from the database, and not ready once the shutdown has begun.
func NewHealth ¶
NewHealth checks readiness with ping, which runs SELECT 1 on the main pool within a second.
func (*Health) Live ¶
func (h *Health) Live(w http.ResponseWriter, _ *http.Request)
Live is getHealthLive: 200 without checks.
func (*Health) Ready ¶
func (h *Health) Ready(w http.ResponseWriter, r *http.Request)
Ready is getHealthReady: 200 while the database answers, 503 otherwise and during the shutdown.
func (*Health) ShuttingDown ¶
func (h *Health) ShuttingDown()
ShuttingDown makes readiness answer 503 from now on.
type ListenerError ¶
ListenerError is a listener that stopped serving.
func (*ListenerError) Error ¶
func (e *ListenerError) Error() string
func (*ListenerError) Unwrap ¶
func (e *ListenerError) Unwrap() error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the running listeners.
func Start ¶
Start listens on every address, then serves; a listener that cannot listen closes the others and is an error naming its variable. ctx is the base context of every request.
func (*Server) Addrs ¶
Addrs are the addresses the listeners are bound to; Ingest equals App when one port serves both.
func (*Server) Errors ¶
Errors delivers a ListenerError for each listener that stops serving on its own.
func (*Server) Shutdown ¶
Shutdown stops accepting connections and waits for the requests in progress until ctx ends; then it closes the remaining connections and returns ctx's error. The app and ingest listeners drain first and the internal listener last, so that readiness keeps answering, with 503, and metrics stay scrapable during the drain.