doorman: Index | Files

package doorman

import ""

Package doorman is a client library for Doorman, a global, distributed, client side rate limitting service.


Package Files



var (

    // ErrDuplicateResourceID is an error indicating the requested
    // resource was already claimed from this client.
    ErrDuplicateResourceID = errors.New("duplicate resource ID")

    // ErrInvalidWants indicates that wants must be a postive number > 0
    ErrInvalidWants = errors.New("wants must be > 0.0")

type Client Uses

type Client struct {
    // contains filtered or unexported fields

Client is a Doorman client.

func New Uses

func New(addr string, opts ...Option) (*Client, error)

New creates a new client connected to server available at addr. It will use the hostname to generate a client id. If you need finer control over the client's id, use NewWithID.

func NewWithID Uses

func NewWithID(addr string, id string, opts ...Option) (*Client, error)

NewWithID creates a new client connected to server available at addr, identifying using the custom id provided.

func (*Client) Close Uses

func (client *Client) Close()

Close closes the doorman client.

func (*Client) GetMaster Uses

func (client *Client) GetMaster() string

GetMaster returns the address of the Doorman master we are connected to.

func (*Client) Resource Uses

func (client *Client) Resource(id string, capacity float64) (Resource, error)

Resource requests capacity from the resource identified by id and with priority 0. If the resource with this id has been already claimed from this client, it will return ErrDuplicateResourceID.

func (*Client) ResourceWithPriority Uses

func (client *Client) ResourceWithPriority(id string, capacity float64, priority int64) (Resource, error)

ResourceWithPriority requests capacity from the resource identified by id, with the provided priority.

type Option Uses

type Option connection.Option

Option configures the client's connection parameters.

func DialOpts Uses

func DialOpts(dialOpts ...rpc.DialOption) Option

DialOpts sets dial options for the client's connection with the server.

func MinimumRefreshInterval Uses

func MinimumRefreshInterval(t time.Duration) Option

MinimumRefreshInterval sets the minimum refresh interval for establishing the client's connection with the server.

type Resource Uses

type Resource interface {
    // Capacity returns a channel on which the available capacity
    // will be sent.
    Capacity() chan float64

    // Ask requests a new capacity for this resource. If the resource
    // was already released this call has no effect.
    Ask(float64) error

    // Release releases any capacity held by this client.
    Release() error

Resource represents a resource managed by a doorman server.

Package doorman imports 13 packages (graph) and is imported by 7 packages. Updated 2016-11-17. Refresh now. Tools for package owners.