Documentation
¶
Overview ¶
Package httpkit provides an HTTP server with Uber Fx integration. It includes configuration loading, optional pprof endpoints, structured logging, graceful shutdown, and a simple mechanism for services to register their own handlers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Module ¶
Module provides HTTP server configuration and lifecycle management for Fx.
It wires:
- Config from "http" subtree
- net.Listener bound to Addr
- *http.ServeMux with optional pprof + group handlers
- Server lifecycle with graceful shutdown
To register routes from a service:
fx.Provide(func() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello"))
})
})
Or directly provide a route:
fx.Provide(func() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("pong"))
})
})
func NewListener ¶
NewListener binds a TCP listener to the configured Addr.
Types ¶
type Config ¶
type Config struct {
// Addr is the listen address, e.g. ":8080".
Addr string `yaml:"addr" validate:"required"`
// ReadTimeoutMS sets the maximum duration for reading the request in ms.
ReadTimeoutMS int `yaml:"read_timeout_ms" validate:"gte=0"`
// WriteTimeoutMS sets the maximum duration for writing the response in ms.
WriteTimeoutMS int `yaml:"write_timeout_ms" validate:"gte=0"`
// EnablePprof enables /debug/pprof endpoints if true. Default false.
EnablePprof bool `yaml:"enable_pprof"`
}
Config holds HTTP server configuration.
Click to show internal directories.
Click to hide internal directories.