tuhochi / ratelimit

Simple, thread-safe Go rate-limiter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RateLimit

Build Status 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 (
  "github.com/bsm/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

About

Simple, thread-safe Go rate-limiter

License:MIT License


Languages

Language:Go 97.7%Language:Makefile 2.3%