bitly/go-hostpool — pull request #1 by danielhfrank (2013-05-01 17:52:17+00:00)
Title: Internal API changes

Just wanted to put some work I've done on the internal api changes up for folks to look at. The main goal of all this stuff is to increase the separation between the epsilon-greedy stuff and the standard hostpool so they can be composed as desired. I'll try to summarize the main changes:

* The `epsilonGreedyHostPoolResponse` keeps a pointer to a `epsilonGreedyHostPool` struct, not the interface. Internally it embeds a `HostPoolResponse` - the interface, not the basic struct impl.
* The `epsilonGreedyHostPool` embeds the `HostPool` interface, not the basic struct impl
* The various `HostPoolResponse` impls no longer have a `sync.Once`. I don't think there should be any expectation that they be threadsafe
* The `HostPool` interface now has a private `selectHost` method to produce a `HostPoolResponse` from a host string. This also takes care of any state changes involved in selecting that host, such as dealing with retry time and starting a time for epsilonGreedy operation
* `getRoundRobin` and `getEpsilonGreedy` just select a hostname. The `selectHost` method takes care of other state changes involved in delivering the `HostResponse` to the user.

I have some more changes in mind that I would eventually like to make in the service of the separation I mentioned, but I think that this is a good place to start. The tests pass, though I did have to change them slightly: I have to make a couple of type assertions, and I had to remove one line that tested the `sync.Once` functionality of the `HostPoolResponse`s.

cc @jehiah @mreiferson