Reputation: 6394
I know http.Client in Go language has connection pool in type Transport
But there is no Transport in http.Server
I wish to access server's pool.
Update
I am learning Go source code https://code.google.com/p/go/source/browse/src/pkg/net/http/server.go#1087
It seems that this function has the answer that there is no Pool.
May be someone knows how to override that function? Do I have to create a hole copy of package?
Upvotes: 5
Views: 4109
Reputation: 11377
EDIT: Note that the Transport struct corresponds to an http client, not an http server
The Transport struct lives here: https://code.google.com/p/go/source/browse/src/pkg/net/http/transport.go
In that struct there are a few members of interest:
idleConn
idleConnCh
reqConn
I think strictly speaking this is what you are asking about.
However those are not exported and it's pretty clear the author did not intend those to be modified by from other packages.
I would suggest having a look at CloseIdleConnections
, CancelRequest
- those seem to be the exported functions that deal with the connection pool, maybe that solves part of your problem.
Otherwise, you're basically up against "it wasn't designed to do that". There is apparently (someone might come along and correct me on this, but I haven't see how) no way to extend built-in types in a fashion that lets you access members which are only visible within it's package (i.e. members that start with a lower case letter). Meaning you can't access those members of the Transport struct without modifying the source of the http
package (or copying it and making your own).
Upvotes: 1
Reputation: 6394
I got answer on go-nuts mailing list.
https://groups.google.com/forum/#!topic/golang-nuts/eoBsx0Sl3Co
Upvotes: 3