Simple, thread-safe Go rate-limiter (evacuated from NSA/Microsoft Github... not to be confused with golang-github-jacobsa-ratelimit-dev or golang-github-juju-ratelimit-dev )
anonymous 7da77c02c4 preliminary building debian package | 5 gadi atpakaļ | |
---|---|---|
debian | 5 gadi atpakaļ | |
.travis.yml | 7 gadi atpakaļ | |
Gopkg.lock | 7 gadi atpakaļ | |
Gopkg.toml | 7 gadi atpakaļ | |
LICENSE | 7 gadi atpakaļ | |
Makefile | 7 gadi atpakaļ | |
README.md | 5 gadi atpakaļ | |
ratelimit.go | 8 gadi atpakaļ | |
ratelimit_test.go | 7 gadi atpakaļ |
Simple, thread-safe Go rate-limiter. Inspired by Antti Huima's algorithm on http://stackoverflow.com/a/668327
package main
import (
"notabug.org/themusicgod1/ratelimit"
"log"
)
func main() {
// Create a new rate-limiter, allowing up-to 10 calls
// per second
rl := ratelimit.New(10, time.Second)
for i:=0; i<20; i++ {
if rl.Limit() {
fmt.Println("DOH! Over limit!")
} else {
fmt.Println("OK")
}
}
}
Full documentation is available on GoDoc