httpratelimit

package module
v0.0.0-...-0fb6186 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2016 License: MIT Imports: 6 Imported by: 0

README

httpratelimit Build Status Coverage GoDoc

allows HTTP Transport supporting rate limiting policies

inspired by: https://github.com/facebookgo/httpcontrol

Goals

To provide HTTP rate limit policies.

  • MonitoringRateLimit - only monitors rate limit status for debugging/MonitoringRateLimit
  • ResponseErrorRateLimit - rate limit intercept request if exceeded and provide error HTTP response (avoid hitting real API server to avoid blacklisting and throttling)
  • ThrottlingRateLimit - provide a throttling mechanism to spread out API requests evenly across rate limit time period
    • blocks requests and waits until it can schedule request that would result in an even request distribution across rate limit time period

Provide concrete rate limit configuration for specific HTTP API Services:

Documentation

Overview

Package httpratelimit provides a rate limit enabled http Transport.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ByteCache

type ByteCache interface {
	Store(key string, value []byte, timeout time.Duration) error
	Get(key string) ([]byte, error)
}

type Cache

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

func NewCache

func NewCache(defaultExpiration, cleanupInterval time.Duration) *Cache

func NewDefaultCache

func NewDefaultCache() *Cache

func (*Cache) Get

func (c *Cache) Get(key string) ([]byte, error)

func (*Cache) Store

func (c *Cache) Store(key string, value []byte, timeout time.Duration) error

type Config

type Config interface {
	// Generates the cache key for the given http.Request. An empty string will
	// disable caching.
	Key(req *http.Request) string

	// Provides the max cache age for the given request/response pair. A zero
	// value will disable caching for the pair. The request is available via
	// res.Request.
	MaxAge(res *http.Response) time.Duration
}

func CacheByPath

func CacheByPath(timeout time.Duration) Config

This caches against the host + path (ignoring scheme, auth, query etc) for the specified duration.

func CacheByURL

func CacheByURL(timeout time.Duration) Config

This caches against the entire URL for the specified duration.

type Transport

type Transport struct {
	Config    Config            // Provides cache key & timeout logic.
	ByteCache ByteCache         // Cache where serialized responses will be stored.
	Transport http.RoundTripper // The underlying http.RoundTripper for actual requests.
}

Cache enabled http.Transport.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (res *http.Response, err error)

A cache enabled RoundTrip.

Jump to

Keyboard shortcuts

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