I'd like to be able to copy the http.DefaultTransport then tweak it for
my app.

http.DefaultTransport has a lot of good defaults in, so copying it then
tweaking it makes it forward compatible with changes (a good example of
a recent change would be the ExpectContinueTimeout).

You might think you could just do

  newTransport := new(http.Transport)
  *newTransport = *http.DefaultTransport
  new.Transport.MaxIdleConns = myTweakedValue

But if you do that then go vet moans about copying mutexes (for very
good reasons).

The best I could come up with was using a bit of reflection

https://play.golang.org/p/l2mkCTZSzL

Is there a better way?

Should making an http.Transport with the default settings in be
something the standard library should support?  Maybe a
NewDefaultTransport() function?

-- 
Nick Craig-Wood <n...@craig-wood.com> -- http://www.craig-wood.com/nick

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