httpserver

package
v1.73.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httpserver builds the HTTP transport every service in this repo runs on: CORS, access logging with correlation IDs, and the Serve/Shutdown lifecycle pkg/boot.Service expects. A service package supplies only its own routes and gets the rest for free instead of rebuilding http.Server and its middleware chain by hand.

One Server hosts any number of Registrations on one mux behind one CORS and access-logging layer; http.ServeMux precedence decides which route a request gets, and panics at boot on a pattern two of them claim.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name      string
	Component string
	Address   string

	CORS     config.CORSConfig
	Timeouts config.HTTPDefaults

	// Registrations are the hosted services: one for a standalone binary.
	Registrations []Registration
}

Config is what pkg/boot.Boot builds from Registrations plus what only the platform layer decides: name, listen address, and the CORS/timeout defaults every HTTP server in this repo shares.

type Registration

type Registration struct {
	// ServiceTokenHeader, if set, is added to CORS's allowed headers so a
	// browser-based service-to-service caller can present it; leave empty
	// if the service takes no service-token header.
	ServiceTokenHeader string

	// SetupRoutes registers the service's handlers on mux. Required.
	SetupRoutes func(mux *http.ServeMux)

	// Closers are closed, in order, after the HTTP server has shut down.
	Closers []io.Closer
}

Registration is what a service provides: its routes, never the transport around them.

type Server

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

func New

func New(cfg Config) *Server

New builds a Server hosting cfg.Registrations. Like http.ServeMux it panics on programmer error: an empty registration list, or a pattern two registrations both claim.

func (*Server) Address

func (s *Server) Address() string

func (*Server) Handler

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

Handler returns the fully-wrapped handler (CORS, then access logging), for tests that drive it directly instead of over a listener.

func (*Server) Logger

func (s *Server) Logger() *logrus.Entry

func (*Server) Name

func (s *Server) Name() string

func (*Server) Serve

func (s *Server) Serve() error

func (*Server) Shutdown

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

Jump to

Keyboard shortcuts

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