~egtann/lanhttp

efa94c6cc18ed00275466e9b3580f9e6d5d216e3 — Evan Tann 1 year, 2 months ago d302634
improve failure case, add helper
3 files changed, 15 insertions(+), 1 deletions(-)

M go.mod
M go.sum
M lanhttp.go
M go.mod => go.mod +2 -0
@@ 1,3 1,5 @@
module github.com/egtann/lanhttp

go 1.13

require github.com/hashicorp/go-cleanhttp v0.5.1

M go.sum => go.sum +2 -0
@@ 0,0 1,2 @@
github.com/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=

M lanhttp.go => lanhttp.go +11 -1
@@ 11,6 11,8 @@ import (
	"strings"
	"sync"
	"time"

	"github.com/hashicorp/go-cleanhttp"
)

type Client struct {


@@ 71,6 73,12 @@ func NewClient(client HTTPClient) *Client {
	}
}

func DefaultClient(timeout time.Duration) *Client {
	cc := cleanhttp.DefaultClient()
	cc.Timeout = timeout
	return NewClient(cc)
}

// WithLogger replaces the logger of a client in a threadsafe way. This can be
// used for instance to load up the internal LAN clients immediately, then
// update the logger with new settings later in the program, e.g. after


@@ 132,7 140,9 @@ func (c *Client) first(urls []string, timeout time.Duration) Routes {
	case routes := <-ch:
		return routes
	case <-time.After(timeout):
		return Routes{}
		// Default to keeping our existing routes, so a slowdown from
		// the reverse proxy doesn't cause an outage
		return c.Routes()
	}
}