doorman

package
v0.0.0-...-e2b69e1 Latest Latest
Warning

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

Go to latest
Published: May 2, 2016 License: Apache-2.0 Imports: 13 Imported by: 9

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

This section is empty.

Types

type Client

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

Client is a Doorman client.

func New

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

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

func (client *Client) Close()

Close closes the doorman client.

func (*Client) GetMaster

func (client *Client) GetMaster() string

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

func (*Client) Resource

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

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

type Option connection.Option

Option configures the client's connection parameters.

func DialOpts

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

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

func MinimumRefreshInterval

func MinimumRefreshInterval(t time.Duration) Option

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

type Resource

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.

Jump to

Keyboard shortcuts

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