Documentation ¶
Index ¶
- Variables
- func WithClient(c *Client) func(*Pool)
- func WithClientTransport(t http.RoundTripper) func(*Client)
- func WithHashFn(h consistenthash.Hash) func(*Client)
- func WithPath(p string) func(*Client)
- func WithProxyTransport(t http.RoundTripper) func(*Pool)
- func WithReplicas(r int) func(*Client)
- type Client
- type Pool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( PluginConfig = &forwardcacheConfig{ done: make(chan struct{}), } )
Config ...
Functions ¶
func WithClient ¶
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 ¶
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 ¶
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 ¶
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 ¶
HTTPClient returns an http.Client that uses the pool as its transport.
func (*Client) RoundTrip ¶
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 ¶
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 ¶
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 ¶
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. |