Go's http.Client
makes requests using a http.RoundTripper
. This, in turn, uses a net.Dialer
to establish the outbound network connections. net.Dialer
has a field LocalAddr
which specifies the local address from which the connections will be made. You can use your own Client
, with your own RoundTripper
, with your own net.Dialer
, specifying the LocalAddr
you want to use. You can see how each of these is instantiated in the stdlib code linked from the documentation, and copy the mechanisms used to create the default instances to maintain default behavior while overriding the LocalAddr
as needed.