lanhttp wraps http.Client to automatically route internal traffic (denoted by *.internal) URLs to internal endpoints, and route other traffic normally over the internet. This is an alternative to consul and other DNS-level routing.

It distributes traffic randomly among the internal IPs.


import ""
Expand ▾ Collapse ▴




This section is empty.


This section is empty.


This section is empty.


type Client

type Client struct {
	// contains filtered or unexported fields

func DefaultClient

func DefaultClient(timeout time.Duration) *Client

func NewClient

func NewClient(client HTTPClient) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

func (*Client) ResolveHost

func (c *Client) ResolveHost(uri *url.URL) *url.URL

ResolveHost from a URL to a specific IP if internal, otherwise return the URL unmodified.

func (*Client) Routes

func (c *Client) Routes() Routes

Routes returns a copy of all live backend IPs.

func (*Client) StartUpdating

func (c *Client) StartUpdating(urls []string, every time.Duration)

StartUpdating live backends with an initial, synchronous update before continuing. Try all URLs simultaneously and use results from the first reply. Note that even when this fails, we still allow the code to continue... Just don't expect internal IPs to route until the servers come online.

func (*Client) StopUpdating

func (c *Client) StopUpdating()

func (*Client) WithLogger

func (c *Client) WithLogger(lg Logger) *Client

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 environment variables are loaded and you try to connect to internal services.

func (*Client) WithRoutes

func (c *Client) WithRoutes(routes Routes) *Client

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)

type Logger

type Logger interface{ Printf(string, ...interface{}) }

Logger is the public logging interface. We wrap this with our own logger to provide some more control.

type Routes

type Routes map[string][]string

Source Files