server

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server hosts the HTTP API, the OpenAPI spec and the metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestID

func RequestID(ctx context.Context) string

RequestID returns the request's ID, or "" outside a request.

Types

type Config

type Config struct {
	// Listen is the TCP address to serve on, e.g. 127.0.0.1:8080.
	Listen string
	// Version is reported by the health endpoint.
	Version string
	// FetchUserHeader names the request header that says who fetched the
	// list, such as one an authenticating proxy sets, for the fetch metric.
	FetchUserHeader string
	// FetchAddressHeader names the request header holding the client's
	// address, set by the proxy in front; empty records no addresses.
	FetchAddressHeader string
	// TrustedProxies are the peers whose fetch headers are believed; empty
	// believes every peer.
	TrustedProxies []netip.Prefix
}

Config holds what the server needs to start.

type Lists

type Lists interface {
	Current() *publish.Current
	LastSuccess() time.Time
	// Seen is told who fetched the list, and from where.
	Seen(user, address string)
}

Lists is where the served list comes from.

type Metrics

type Metrics interface {
	Counter(name, help string)
	Add(name string, v float64, labels ...string)
	Write(w io.Writer) error
}

Metrics is the registry the server counts fetches in and serves.

type Server

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

Server serves /api/v1, the OpenAPI spec and /metrics on one listener.

func New

func New(log *slog.Logger, cfg Config, lists Lists, metrics Metrics) (*Server, error)

New builds the route table.

func (*Server) Handler

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

Handler returns the served handler (the route table behind the access log), for tests.

func (*Server) Run

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

Run serves until ctx is cancelled, then shuts down gracefully.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Serve serves on ln until ctx is cancelled, then shuts down gracefully.

Jump to

Keyboard shortcuts

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