Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Overview

Package server holds HTTP routing, middleware and handlers.

Handlers know neither SQL (invariant 5) nor auth providers (invariant 4): data access goes through repository.Store, and identity arrives as a player_id on the request context.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Build

type Build struct {
	Version    string
	CommitTime string
}

Build is what this binary can say about itself, set at link time.

Two values rather than one string, so the page can show them as two things: which commit, and how old it is. CommitTime is when that commit was made, not when the binary was built — a build clock would make two images from one commit differ, and "is the same thing running here and there" is the question this exists to answer.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server bundles configuration, dependencies and routing.

func New

func New(cfg config.Config, store repository.Store, log *slog.Logger, a auth.SessionAuthenticator, build Build) *Server

New wires up the server. The authenticator is an interface so that later providers (OIDC, WebAuthn) take effect without touching any handler.

func (*Server) GrantBootstrapAdmin

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

GrantBootstrapAdmin gives the flag to the player SP_BOOTSTRAP_ADMIN names.

Run at every start, not only the first. Somebody who withdraws the flag from the last admin gets back in by restarting with the variable set, and not by opening psql — which is the price issue #73 puts on a flag and what docs/adr/0008 answers.

A name nobody has is a warning, not a failure. The variable is often set before the person it names has joined, and refusing to start over it would turn a typo into an outage.

func (*Server) Handler

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

Handler returns the fully wired HTTP handler.

func (*Server) MetricsHandler added in v0.8.0

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

MetricsHandler is what the metrics listener serves, or nil when SP_METRICS_ADDR is unset.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the server — and the metrics listener, when there is one — and stops both gracefully once ctx is cancelled.

Jump to

Keyboard shortcuts

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