Skip to content

aide-family/rate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A rate limiter with a fixed window

quick start

go get github.com/aide-family/rate
package main

import (
	"fmt"
	"github.com/aide-family/rate"
	"time"
)

func main() {
	// This limiter allows for the generation of 3 tokens within a 10 second window with a minimum interval of 2 seconds.
	limiter := rate.NewLimiter(3, 10*time.Second, 2*time.Second)
	if limiter.Allow() {
		fmt.Println("allow")
	}else{
		fmt.Println("not allow")
    }
}