On Wed, Oct 17, 2018 at 11:13 AM Kyle Butz <kyleb...@gmail.com> wrote:
>
> Thanks for the help!
>
> So, a copy of the pointer to the Transport used to initialize 
> DefaultTransport would be the same, global instance of the Transport?
>
> Does that mean that every time I instantiate a new client, I am using the 
> same Transport?

That appears to be the case.

>
> On Wednesday, October 17, 2018 at 11:35:52 AM UTC-5, Burak Serdar wrote:
>>
>> On Wed, Oct 17, 2018 at 10:30 AM Kyle Butz <kyle...@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...@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.

-- 
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.

Reply via email to