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

httpserver

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package httpserver is the HTTP entry of ermite: the router, the security headers, the request log and the graceful shutdown. Routes are added here as the other adapters arrive: /-/health and the routes given in Config.

Index

Constants

View Source
const APIPrefix = "/-/api"

APIPrefix is where the API is mounted.

View Source
const ShutdownTimeout = 10 * time.Second

ShutdownTimeout is how long Run waits for requests in flight after the context ends.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check func(ctx context.Context) error

Check reports whether a dependency works. A nil result means healthy.

func DirWritable

func DirWritable(dir string) Check

DirWritable returns a Check that creates and removes a file in dir.

type Config

type Config struct {
	// Addr is the listen address, "host:port".
	Addr string
	// PublicURL is the public base URL of the server. When it is https://,
	// every response carries Strict-Transport-Security.
	PublicURL string
	// HealthChecks run on GET /-/health, at most once per healthCacheTTL
	// (the answer is cached, the endpoint being unauthenticated); one
	// failure answers 503.
	HealthChecks []Check
	// Routes are added to the router next to /-/health.
	Routes []Route
	// API serves the ConnectRPC API under /-/api/ (the prefix is stripped, so
	// it sees "/ermite.RepoService/ListRepos"). Nil serves none.
	API http.Handler
	// OnShutdown functions run, each in its own goroutine, when the graceful
	// shutdown begins. Use them to end long-lived responses such as event
	// streams, which the shutdown would otherwise wait for.
	OnShutdown []func()
}

Config configures a Server.

type Route

type Route struct {
	// Pattern is a net/http.ServeMux pattern, such as "GET /{repo}/info/refs".
	// It must not overlap the /-/ routes of the server.
	Pattern string
	Handler http.Handler
}

Route mounts a handler on the router.

type Server

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

Server is the HTTP server of ermite.

func New

func New(cfg Config) *Server

New builds the server and its routes.

func (*Server) Handler

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

Handler returns the root handler, for tests.

func (*Server) Run

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

Run listens on the configured address and serves until ctx ends, then shuts down gracefully within ShutdownTimeout. It returns nil after a clean shutdown. The logger of ctx is used for the server and its requests.

func (*Server) Serve

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

Serve is Run on an existing listener, which it closes.

Jump to

Keyboard shortcuts

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