Documentation
¶
Overview ¶
Package httpsrv provides an HTTP server integrated with BAT application lifecycle. It wraps net/http.Server with graceful shutdown support and context decoration.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Addr string
Listener func() (net.Listener, error)
DisableGeneralOptionsHandler bool
ReadTimeout string
ReadHeaderTimeout string
WriteTimeout string
IdleTimeout string
MaxHeaderBytes int
// contains filtered or unexported fields
}
func (Config) BuildServer ¶
BuildServer creates an http.Server from this config with the given handler.
func (Config) New ¶
New creates a Service from a pre-built http.Handler. Use this when you provide your own handler — a third-party router, a manually constructed mux, or the result of Build.
func (Config) NewFromRoutes ¶
func (cfg Config) NewFromRoutes(rs []Route, mdws []Middleware, cd []bat.CtxDecorator) (*Service, error)
NewFromRoutes collects Routes and Middlewares injected by the DI container, assembles them via Build, and creates the Service. Pass it directly to bat.Provide: bat.Provide(cfg.NewFromRoutes)
type Middleware ¶
Middleware is a standard HTTP middleware. Register multiple middlewares for DI-assembled servers via bat.SupplyGroup[Middleware].
type Route ¶
type Route interface {
Register(mux Mux)
}
Route is implemented by anything that can register itself onto a Mux. Use Endpoint for a single pattern, Group to compose multiple Routes.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service wraps an http.Server with BAT lifecycle integration.
func New ¶
func New(hs *http.Server, cd []bat.CtxDecorator) *Service
New creates a Service from a pre-built http.Server and optional context decorators.
func (*Service) Init ¶
func (s *Service) Init(bg bat.BackgroundContext, app bat.PhaseScheduler)
Init registers the service into the BAT lifecycle. It wires Serve at PhaseStart, Shutdown at PhaseShutdown, and Stop at PhaseStop.
func (*Service) Serve ¶
Serve starts the HTTP server. It blocks until the server stops. If no listener or address is configured, it listens on a random localhost port.