http

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package http adapts controller instances to HTTP routing.

Route registration is explicit: controllers implement RouteRegistrar and are invoked via RegisterRoutes. No reflection is used.

NewRouter returns a chi.Router with baseline middleware. Use AsRouter to adapt it to the method-based Router interface.

Index

Constants

This section is empty.

Variables

View Source
var ShutdownTimeout = 30 * time.Second

ShutdownTimeout controls how long the server will wait for in-flight requests to finish after receiving a shutdown signal.

Functions

func NewRouter

func NewRouter() chi.Router

NewRouter creates a chi router with baseline middleware for the HTTP adapter.

func RegisterRoutes

func RegisterRoutes(router Router, controllers map[string]any) error

RegisterRoutes invokes controller route registration functions.

func RequestLogger

func RequestLogger(logger logging.Logger) func(http.Handler) http.Handler

RequestLogger returns an HTTP middleware that logs each request with method, path, status, and duration.

func Serve

func Serve(addr string, handler http.Handler) error

Serve starts an HTTP server on the given address using the provided handler. It handles SIGINT and SIGTERM for graceful shutdown.

Types

type RouteRegistrar

type RouteRegistrar interface {
	RegisterRoutes(router Router)
}

RouteRegistrar defines a controller that can register its HTTP routes.

type RouteRegistrationError

type RouteRegistrationError struct {
	Name string
}

RouteRegistrationError indicates a controller does not expose route registration.

func (*RouteRegistrationError) Error

func (e *RouteRegistrationError) Error() string

type Router

type Router interface {
	Handle(method string, pattern string, handler http.Handler)
	Group(pattern string, fn func(Router))
	Use(middlewares ...func(http.Handler) http.Handler)
}

Router provides a minimal method-based handler registration API.

func AsRouter

func AsRouter(router chi.Router) Router

AsRouter adapts a chi router to the minimal Router interface.

Jump to

Keyboard shortcuts

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