httpserver

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(opts ...RouterOption) *chi.Mux

NewRouter returns a chi router with RequestID, trusted-proxy client IP (clientip), request logger, Recoverer and Timeout.

func Run

func Run(opts Options)

Run starts the server and blocks until SIGINT/SIGTERM.

func SecurityHeaders added in v0.1.3

func SecurityHeaders(next http.Handler) http.Handler

SecurityHeaders sets nosniff, anti-clickjacking, Referrer-Policy, a baseline CSP and (when HTTPSERVER_HSTS or COOKIE_SECURE is set) HSTS.

func Serve

func Serve(ctx context.Context, opts Options) error

Serve listens until ctx is cancelled, then shuts down with a 10s timeout.

Types

type Options

type Options struct {
	Addr    string
	Handler http.Handler
}

Options configures ListenAndServe / Run.

type RouterOption

type RouterOption func(*routerOptions)

RouterOption configures NewRouter.

func WithLogger

func WithLogger(mw func(http.Handler) http.Handler) RouterOption

WithLogger replaces the default request logger middleware.

func WithTimeout

func WithTimeout(d time.Duration) RouterOption

WithTimeout sets chi Timeout middleware. Zero duration skips Timeout.

func WithoutLogger

func WithoutLogger() RouterOption

WithoutLogger skips request logging middleware.

func WithoutTimeout

func WithoutTimeout() RouterOption

WithoutTimeout omits chi Timeout middleware.

Jump to

Keyboard shortcuts

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