Giter Club home page Giter Club logo

throttled's Introduction

Throttled build status GoDoc

Package throttled implements rate limiting access to resources such as HTTP endpoints.

The 2.0.0 release made some major changes to the throttled API. If this change broke your code in problematic ways or you wish a feature of the old API had been retained, please open an issue. We don't guarantee any particular changes but would like to hear more about what our users need. Thanks!

Installation

throttled uses gopkg.in for semantic versioning: go get gopkg.in/throttled/throttled.v2

Documentation

API documentation is available on godoc.org. The following example demonstrates the usage of HTTPLimiter for rate-limiting access to an http.Handler to 20 requests per path per minute with bursts of up to 5 additional requests:

store, err := memstore.New(65536)
if err != nil {
	log.Fatal(err)
}

quota := throttled.RateQuota{throttled.PerMin(20), 5}
rateLimiter, err := throttled.NewGCRARateLimiter(store, quota)
if err != nil {
	log.Fatal(err)
}

httpRateLimiter := throttled.HTTPRateLimiter{
	RateLimiter: rateLimiter,
	VaryBy:      &throttled.VaryBy{Path: true},
}

http.ListenAndServe(":8080", httpRateLimiter.RateLimit(myHandler))

Contributing

Since throttled uses gopkg.in for versioning, running go get against a fork or cloning from Github to the default path will break imports. Instead, use the following process for setting up your environment and contributing:

# Retrieve the source and dependencies.
go get gopkg.in/throttled/throttled.v2/...

# Fork the project on Github. For all following directions replace
# <username> with your Github username. Add your fork as a remote.
cd $GOPATH/src/gopkg.in/throttled/throttled.v2
git remote add fork [email protected]:<username>/throttled.git

# Create a branch, make your changes, test them and commit.
git checkout -b my-new-feature
# <do some work>
make test 
git commit -a
git push -u fork my-new-feature

When your changes are ready, open a pull request using "compare across forks".

License

The BSD 3-clause license. Copyright (c) 2014 Martin Angers and Contributors.

throttled's People

Contributors

mna avatar andrew-stripe avatar brandur avatar metcalf avatar yazinsai avatar

Watchers

Terry Huang avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.