Documentation
¶
Overview ¶
Package stdhttpclientfx provides the one HTTP client an application sends its outgoing requests with, so behaviour that every request needs, such as logging, is added once, as middleware, instead of in each client.
The client logs every request it sends, and runs the middleware that other modules provide with AsMiddleware. It sets no overall timeout: callers bound each request with its context. It does not retry.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AsMiddleware ¶
AsMiddleware annotates a constructor that returns a Middleware, for fx.Provide, so the client runs it.
Types ¶
type Config ¶
type Config struct {
// MaxIdleConnsPerHost is how many idle connections the client keeps open
// to each host. Go's default of 2 makes concurrent workers calling one
// service open and close connections all the time.
MaxIdleConnsPerHost int `env:"MAX_IDLE_CONNS_PER_HOST" envDefault:"64"`
}
Config configures the module, from the environment with the STDHTTPCLIENT_ prefix.
type Middleware ¶
type Middleware struct {
Name string
Wrap func(http.RoundTripper) http.RoundTripper
}
Middleware wraps the client's transport. Name orders it: the client runs middleware in order of name, the first outermost, so it sees a request first and its response last.
type Params ¶
type Params struct {
fx.In
fx.Lifecycle
Config Config
Logs *zap.Logger
Middleware []Middleware `group:"stdhttpclient.middleware"`
}
Params is the fx input for New.
type Result ¶
type Result struct {
fx.Out
// Client sends requests through Transport.
Client *http.Client
// Transport is the client's transport, with the logging and middleware,
// for libraries that take a transport rather than a client.
Transport http.RoundTripper
}
Result is the fx output of New.