server

package
v0.1.11 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 12 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 is the HTTP server of the service and its graceful stop.

Index

Constants

This section is empty.

Variables

View Source
var ErrShutdown = errors.New("server: graceful shutdown")

ErrShutdown marks a stop that failed other than by running out of time: what Run returns then is a failure of the shutdown, not of serving.

Functions

func Routes

func Routes(log *slog.Logger, appOrigin string, mount func(*http.ServeMux)) http.Handler

Routes is the service's handler: the health check, and whatever mount puts on the mux — the methods of the contract, by the Connect server (R33). A panic in any of them is answered here, and CORS is answered to appOrigin, when it is set, on every path and every answer.

The router is the standard library's: a Connect handler is an http.Handler, and a pattern with a method is all the routes need.

Types

type Server

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

Server is the HTTP server and its graceful stop.

func New

func New(cfg *config.Config, log *slog.Logger, handler http.Handler) *Server

New builds the server of cfg, serving handler and writing to log.

func (*Server) Addr

func (s *Server) Addr() string

Addr is the address the server is bound to, empty before Listen. It is safe to call while the server is starting or serving.

func (*Server) Listen

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

Listen binds the port without serving on it yet. Run binds it itself when nothing did, but the process calls Listen first: binding early is how a port that is already taken is reported as a failed start, before the service says it has started, rather than swallowed by the goroutine inside Run.

func (*Server) Run

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

Run serves until ctx is cancelled, then stops gracefully. The stop is driven by the context rather than by a signal handler of its own, so that every part of the process stops for the same reason at the same moment.

A request still being handled when the drain's share of the way out is spent is cut off rather than waited for, and that is still the stop that was asked for: the line saying so is a warning, and Run returns no error. A failure is what nobody asked for — a server that stopped serving on its own.

Jump to

Keyboard shortcuts

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