On Wed, Oct 17, 2018 at 10:30 AM Kyle Butz <kyleb...@gmail.com> wrote: > > Hi All! > > I'm having trouble understanding whether a new http.Client{} with no > Transport set will use a new copy of DefaultTransport, or the global? > > From client.go: > > func (c *Client) transport() RoundTripper { > if c.Transport != nil { > return c.Transport > } > return DefaultTransport > } > > DefaultTransport's definition from transport.go, as a pointer to a Transport > struct: > > var DefaultTransport RoundTripper = &Transport{ > Proxy: ProxyFromEnvironment, > DialContext: (&net.Dialer{ > Timeout: 30 * time.Second, > KeepAlive: 30 * time.Second, > DualStack: true, > }).DialContext, > MaxIdleConns: 100, > IdleConnTimeout: 90 * time.Second, > TLSHandshakeTimeout: 10 * time.Second, > ExpectContinueTimeout: 1 * time.Second, > } > > > It looks like transport() is returning a RoundTripper by value. Does that > mean that "return DefaultTransport" returns a new copy of DefaultTransport, > or just a copy of a pointer to the global DefaultTransport defined in > transport.go?
DefaultTransport is a pointer to a Transport, so when transport() returns DefaultTransport, it returns an interface containing a copy of the pointer to the Transport used to initialize DefaultTransport. > > Thanks for any tips! > Kyle > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.