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 vor 5 Jahren
debian 7da77c02c4 preliminary building debian package vor 5 Jahren
.travis.yml 4a38dca83e Fix CI vor 7 Jahren
Gopkg.lock de6ce9ef6d Bump deps. Update README vor 7 Jahren
Gopkg.toml de6ce9ef6d Bump deps. Update README vor 7 Jahren
LICENSE de6ce9ef6d Bump deps. Update README vor 7 Jahren
Makefile de6ce9ef6d Bump deps. Update README vor 7 Jahren
README.md 7da77c02c4 preliminary building debian package vor 5 Jahren
ratelimit.go db14e16199 Allow to update rate. Added branchmark vor 8 Jahren
ratelimit_test.go b6456d0beb use time.Since instead of time.Now().Sub vor 7 Jahren

README.md

RateLimit

GoDoc Go Report Card License

Simple, thread-safe Go rate-limiter. Inspired by Antti Huima's algorithm on http://stackoverflow.com/a/668327

Example

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")
    }
  }
}

Documentation

Full documentation is available on GoDoc