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 ¶
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.
Click to show internal directories.
Click to hide internal directories.