Documentation ¶
Overview ¶
Package httpserver offers a fx module that utilizes http.Server and httprouter to handle HTTP requests.
Starts:
- HTTP server
Depends on:
- Logger, optional (type: *slog.Logger, name: "logger")
- Routes (type: []Route, group: "routes")
You can configure it using these environment variables:
- HTTP_SERVER_ADDRESS
- HTTP_SERVER_READ_TIMEOUT
- HTTP_SERVER_WRITE_TIMEOUT
- HTTP_SERVER_IDLE_TIMEOUT
- HTTP_SERVER_MAX_HEADER_BYTES
The default values:
- HTTP_SERVER_ADDRESS: ":8080"
- HTTP_SERVER_READ_TIMEOUT: "5s"
- HTTP_SERVER_WRITE_TIMEOUT: "10s"
- HTTP_SERVER_IDLE_TIMEOUT: "120s"
- HTTP_SERVER_MAX_HEADER_BYTES: "1048576" (1MB)
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Module = fx.Module( "http_server", fx.Provide( New, ), fx.Provide( fx.Private, parseConfig, ), fx.Invoke( Start, ), fx.Decorate( wrapLogger, ), )
Module is the http server module.
Functions ¶
Types ¶
type Config ¶
type Config struct { Address string ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration MaxHeaderBytes int }
Config is the http server config.
type Parameter ¶
type Parameter struct { fx.In Logger *slog.Logger `optional:"true"` Routes []Route `group:"routes"` Config Config }
Parameter is the input parameter of the New function.
Click to show internal directories.
Click to hide internal directories.