server

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package server is the v1.3 serve-mode HTTP daemon. It wires the chi router, security middleware, observability endpoints (/health + /metrics), and the read/write API + UI handlers that v1.3-v1.5 fill in across phases. The single entry point is New(), which returns a *Server whose Run(ctx) method blocks until the context cancels — graceful shutdown happens on SIGTERM/SIGINT signaled into the same context.

ADR-015 codifies the UI stack (htmx + Alpine + Tailwind + Preline + vanilla SVG, all go:embed-ed). Single-binary invariant preserved; no Node runtime ships with compliancekit; no CDN is reached at runtime.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Addr is the bind interface; default "127.0.0.1" so the
	// out-of-the-box experience is loopback-only (operator opts into
	// 0.0.0.0 explicitly).
	Addr string

	// Port is the TCP port; default 8080. Override via --port.
	Port int

	// ReadHeaderTimeout caps the time a peer may take to send request
	// headers; protects against slowloris-style starvation.
	ReadHeaderTimeout time.Duration

	// IdleTimeout caps keep-alive idle duration.
	IdleTimeout time.Duration
}

Config carries every knob the daemon takes at startup. Loaded by the CLI subcommand from a mix of compliancekit.yaml + flags + env. Defaults below in Default().

func Default

func Default() Config

Default returns the recommended baseline Config. Tests construct their own; the CLI overlays flags + env onto a Default().

type Server

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

Server is the running daemon. Construct via New(); start via Run().

func New

func New(cfg Config) *Server

New builds the daemon. Wires middleware in the right order (recovery → request-id → real-ip → metrics → security headers), mounts /health + /metrics, and leaves the rest of the routing for future phases to attach via the returned *Server's Router() method.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the bound listen address; useful for tests that need the concrete port when cfg.Port == 0 (ephemeral) is requested.

func (*Server) QueueDepthObserver added in v1.11.0

func (s *Server) QueueDepthObserver() interface{ ObserveQueueDepth(int) }

QueueDepthObserver returns the daemon's worker.DepthObserver implementation so cmd/serve can wire it into the worker pool's autoscale sampler. nil-safe — if the metrics registry isn't yet constructed (zero-value Server), the worker pool silently no-ops.

The interface signature lives in internal/server/worker; we satisfy it without importing the package to avoid a circular dep.

func (*Server) Router

func (s *Server) Router() chi.Router

Router returns the chi router so later-phase packages (api/, auth/, ui/) can mount their routes without re-importing the middleware stack. Callers should attach routes before Run().

func (*Server) Run

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

Run starts the HTTP listener and blocks until ctx is canceled. On cancellation it triggers a graceful shutdown with a 15-second grace period for in-flight requests to drain. Returns nil on a clean shutdown; the underlying http.Server error otherwise.

Directories

Path Synopsis
Package api implements the v1.3+ REST API.
Package api implements the v1.3+ REST API.
Package assets embeds the compiled UI bundle (Tailwind output + vendored htmx, Alpine, Preline) produced by `make ui`.
Package assets embeds the compiled UI bundle (Tailwind output + vendored htmx, Alpine, Preline) produced by `make ui`.
Package auth handles every authentication concern for the v1.3 serve-mode daemon: bcrypt password hashing, DB-backed sessions, double-submit-cookie CSRF protection, and the chi middleware that gates non-public routes.
Package auth handles every authentication concern for the v1.3 serve-mode daemon: bcrypt password hashing, DB-backed sessions, double-submit-cookie CSRF protection, and the chi middleware that gates non-public routes.
Package collab owns the v1.8 collaboration data layer that doesn't fit into the comments package: per-finding assignees, per-resource owners, and resource follower opt-ins.
Package collab owns the v1.8 collaboration data layer that doesn't fit into the comments package: per-finding assignees, per-resource owners, and resource follower opt-ins.
Package comments owns the goldmark+bluemonday pipeline that turns operator-authored markdown into the sanitized HTML cached in the comments table.
Package comments owns the goldmark+bluemonday pipeline that turns operator-authored markdown into the sanitized HTML cached in the comments table.
Package compress is the v1.11 phase 4 HTTP-compression middleware.
Package compress is the v1.11 phase 4 HTTP-compression middleware.
Package etag is the v1.11 phase 5 HTTP caching middleware.
Package etag is the v1.11 phase 5 HTTP caching middleware.
Package events is the v1.6 SSE event bus the daemon uses to push live state changes to subscribed UI / TUI / API clients without polling.
Package events is the v1.6 SSE event bus the daemon uses to push live state changes to subscribed UI / TUI / API clients without polling.
Package logs is the v1.6 phase 6 in-UI log tail.
Package logs is the v1.6 phase 6 in-UI log tail.
Package respcache is the v1.11 phase 6 in-memory LRU for hot list responses.
Package respcache is the v1.11 phase 6 in-memory LRU for hot list responses.
Package slowlog is the v1.11 phase 7 query-budget + slow-query log.
Package slowlog is the v1.11 phase 7 query-budget + slow-query log.
Package store is the persistent-state layer for compliancekit's serve-mode daemon.
Package store is the persistent-state layer for compliancekit's serve-mode daemon.
Package ui mounts the v1.3 minimal UI shell on the daemon's chi router.
Package ui mounts the v1.3 minimal UI shell on the daemon's chi router.
Package webhook handles inbound webhook receivers — GitHub PR / push events + operator-defined generic webhooks.
Package webhook handles inbound webhook receivers — GitHub PR / push events + operator-defined generic webhooks.
Package worker is the v1.3 background job runner.
Package worker is the v1.3 background job runner.

Jump to

Keyboard shortcuts

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