Lets say I have a global net/http
client in my program. Within this program, I have several goroutines making requests with the same global client. E.g.
Golang Pseudocode:
package main
func editTransportAndFetch(c *http.Client) {
c.Transport = &http.Transport{
// Make some unique change here
}
c.Get("https://www.google.com")
}
func main() {
client := http.Client
// Spawns 10 processes
for i := 0; i < 10; i++ {
go editTransportAndFetch(client)
}
}
In this pseudocode example, I demonstrate spawning 10 processes of the http.Transport
being edited. In the case of this example, the same exact change is being made, so maybe interference isn't much of a concern. However, regardless, if these processes are happening concurrently, will one process updating the global client's transport interfere with the transport that a different process may be using?
My ultimate use case is that I would like to have a global client and be able to specify a custom DialTLSContext
but only for certain requests. Requests that I don't want using the DialTLSContext
may be running concurrently as well. I'm worried that if I edit the http.Transport
of the client of one request that it may interfere and cause another request to also use DialTLSContext
even though I don't want it to.