stdhttpclientfx

package
v0.0.265 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func AsMiddleware(constructor any) any

AsMiddleware annotates a constructor that returns a Middleware, for fx.Provide, so the client runs it.

func Provide

func Provide() fx.Option

Provide wires the module.

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.

func New

func New(params Params) (Result, error)

New builds the client.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL