Skip to content

Instantly share code, notes, and snippets.

@shekhar-kamble
Created April 5, 2019 19:18
Show Gist options
  • Save shekhar-kamble/ec775ae8cb4057367a023110d2fb2315 to your computer and use it in GitHub Desktop.
Save shekhar-kamble/ec775ae8cb4057367a023110d2fb2315 to your computer and use it in GitHub Desktop.
example for usage of package "github.com/shekhar-kamble/ratelimit"
package main
import (
"github.com/shekhar-kamble/ratelimit"
"os"
"fmt"
)
func main(){
_ = os.Setenv("LIMITER_REDIS_URL","redis://127.0.0.1:6379")
rl,_ := ratelimit.New(2,10)
for i:=0; i<10;i++ {
if i%2 ==0 {
fmt.Println(i , "divisible by 2" , rl.Allow("2"))
} else if i%5 == 0 {
fmt.Println(i , "divisible by 5" , rl.Allow("5"))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment