httpserver

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package httpserver runs a standard HTTP handler with explicit startup and graceful shutdown. Routing and application middleware belong to the caller.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Address           string
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration
	ShutdownTimeout   time.Duration
	MaxHeaderBytes    int
}

type Server

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

Server is single-use. It owns its listener, but not the supplied handler. Hijacked connections (including WebSockets) are closed when shutdown begins. Protocol-level close frames and application session draining belong to handlers. Keep session work inside the handler so Run can join it before closing dependencies.

func New

func New(cfg Config, handler http.Handler) (*Server, error)

func (*Server) Addr

func (s *Server) Addr() net.Addr

Addr returns the bound address, or nil before startup.

func (*Server) Ready

func (s *Server) Ready() <-chan struct{}

Ready closes once the listener is bound. It does not imply dependency health.

func (*Server) Run

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

Run stops admission on cancellation and drains active handlers. Once the shutdown timeout expires, their contexts are canceled and connections closed. Handlers must honor cancellation; Run joins them before returning.

Jump to

Keyboard shortcuts

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