~egtann/lanhttp

3924c370b2fd57cf242ea1b44bea98367e630d3d — Evan Tann 1 year, 2 months ago 91e1dc1
remove redundant diff check
1 files changed, 10 insertions(+), 17 deletions(-)

M lanhttp.go
M lanhttp.go => lanhttp.go +10 -17
@@ 102,7 102,14 @@ func (c *Client) UpdateRoutes(new Routes) {
	if changed := diff(new, c.Routes()); !changed {
		return
	}
	c.changeRoutes(new)
	c.mu.Lock()
	defer c.mu.Unlock()

	backends := map[string]*backend{}
	for k, ips := range new {
		backends[k] = &backend{IPs: ips}
	}
	c.backends = backends
}

func (c *Client) first(urls []string, timeout time.Duration) Routes {


@@ 154,12 161,12 @@ func (c *Client) first(urls []string, timeout time.Duration) Routes {
// continue... Just don't expect internal IPs to route until the servers come
// online.
func (c *Client) StartUpdating(urls []string, every time.Duration) {
	c.changeRoutes(c.first(urls, every))
	c.UpdateRoutes(c.first(urls, every))
	go func() {
		for {
			select {
			case <-time.After(every):
				c.changeRoutes(c.first(urls, every))
				c.UpdateRoutes(c.first(urls, every))
			case <-c.stop:
				return
			}


@@ 171,20 178,6 @@ func (c *Client) StopUpdating() {
	c.stop <- struct{}{}
}

func (c *Client) changeRoutes(new Routes) {
	if changed := diff(new, c.Routes()); !changed {
		return
	}
	c.mu.Lock()
	defer c.mu.Unlock()

	backends := map[string]*backend{}
	for k, ips := range new {
		backends[k] = &backend{IPs: ips}
	}
	c.backends = backends
}

func (c *Client) Do(req *http.Request) (*http.Response, error) {
	req.URL = c.ResolveHost(req.URL)
	return c.client.Do(req)