forwardcache

package
v0.0.0-...-61f2a12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClient

func WithClient(c *Client) func(*Pool)

WithClient lets you configure a custom pool client. Defaults to NewClient().

func WithClientTransport

func WithClientTransport(t http.RoundTripper) func(*Client)

WithClientTransport lets you configure a custom transport used between the local client and the proxies. Defaults to http.DefaultTransport.

func WithHashFn

func WithHashFn(h consistenthash.Hash) func(*Client)

WithHashFn specifies the hash function of the consistent hash. Defaults to crc32.ChecksumIEEE.

func WithPath

func WithPath(p string) func(*Client)

WithPath specifies the HTTP path that will serve proxy requests. Defaults to "/proxy".

func WithProxyTransport

func WithProxyTransport(t http.RoundTripper) func(*Pool)

WithProxyTransport lets you configure a custom transport used between the local proxy and the origins. Defaults to http.DefaultTransport.

func WithReplicas

func WithReplicas(r int) func(*Client)

WithReplicas specifies the number of key replicas on the consistent hash. Defaults to 50.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a nonparticipating client in the pool. It can issue requests to the pool but not proxy requests for others.

func NewClient

func NewClient(options ...func(*Client)) *Client

NewClient creates a Client.

Example
pool := NewClient()
pool.Set("http://10.0.1.1:3000", "http://10.0.1.2:3000")

// -then-

http.DefaultTransport = pool
http.Get("https://...js/1.5.7/angular.min.js")

// -or-

http.DefaultClient = pool.HTTPClient()
http.Get("https://...js/1.5.7/angular.min.js")

// -or-

c := pool.HTTPClient()
c.Get("https://...js/1.5.7/angular.min.js")
Output:

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns an http.Client that uses the pool as its transport.

func (*Client) RoundTrip

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

RoundTrip makes the request go through one of the proxy. If the local proxy is targetted, it uses the local transport directly. Since Client implements the Roundtripper interface, it can be used as a transport.

func (*Client) Set

func (c *Client) Set(peers ...string)

Set updates the pool's list of peers. Each peer value should be a valid base URL, for example "http://example.net:8000".

type Pool

type Pool struct {
	*Client
	// contains filtered or unexported fields
}

Pool represents all caching proxies spread over 1 or more machines. It also acts as a participating peer.

func NewPool

func NewPool(self string, local httpcache.Cache, options ...func(*Pool)) *Pool

NewPool creates a Pool and registers itself using the specified cache. The returned *Pool implements http.Handler and must be registered manually using http.Handle to serve the local proxy. See LocalProxy()

Example
pool := NewPool("http://10.0.1.1:3000", httpcache.NewMemoryCache())
pool.Set("http://10.0.1.1:3000", "http://10.0.1.2:3000")

// -then-

http.DefaultTransport = pool
http.Get("https://...js/1.5.7/angular.min.js")

// -or-

http.DefaultClient = pool.HTTPClient()
http.Get("https://...js/1.5.7/angular.min.js")

// -or-

c := pool.HTTPClient()
c.Get("https://...js/1.5.7/angular.min.js")

// ...

http.ListenAndServe(":3000", pool.LocalProxy())
Output:

func (*Pool) LocalProxy

func (p *Pool) LocalProxy() http.Handler

LocalProxy returns an http.Handler to be registered using http.Handle for the local proxy to serve requests.

Directories

Path Synopsis
Package consistenthash provides an implementation of a ring hash.
Package consistenthash provides an implementation of a ring hash.
Package lru provides an lru cache algorithm over an existing cache.
Package lru provides an lru cache algorithm over an existing cache.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL