httpserve

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httpserve runs an *http.Server until the process is asked to stop, then shuts it down gracefully.

It owns no routing, no middleware and no configuration: the caller builds the server it wants and hands it over.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(
	ctx context.Context,
	server *http.Server,
	opts Options,
) error

Run starts server and blocks until ctx is cancelled or ListenAndServe fails.

A server closed through Shutdown is not an error.

func Signals

func Signals() (
	context.Context,
	context.CancelFunc,
)

Signals returns a context that is cancelled on SIGINT or SIGTERM, together with the function that releases the handlers.

Types

type Options

type Options struct {
	// Logger records the server lifecycle. Required.
	Logger *slog.Logger

	// ShutdownTimeout bounds the graceful shutdown.
	ShutdownTimeout time.Duration

	// StopSignals, when set, is called as shutdown begins so that a second
	// interrupt terminates the process instead of being swallowed by the
	// shutdown that is already in flight.
	//
	// Pass the CancelFunc returned by Signals.
	StopSignals func()
}

Jump to

Keyboard shortcuts

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