httpx

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package httpx wraps the HTTP-server boilerplate every service main would otherwise duplicate: build an http.Server, run ListenAndServe in a goroutine, wait for ctx to cancel, then Shutdown within a deadline.

Run logs `listening` / `shutting down` lines via zap.L(), so it assumes the caller has already called zap.ReplaceGlobals — every generated service does this through `logger.New` + ReplaceGlobals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, addr string, handler http.Handler) error

Run starts an HTTP server bound to addr serving handler, blocks until ctx cancels, then drains within shutdownTimeout. Returns nil on a clean stop and the listener / shutdown error otherwise.

Typical usage:

ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()

if err := httpx.Run(ctx, ":"+envx.Or("PORT", "8080"), server.New()); err != nil {
    zap.L().Fatal("server stopped", zap.Error(err))
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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