Skip to content

限流适配器 适配令牌桶,漏桶算法限流。

Notifications You must be signed in to change notification settings

leeyongda/ratelimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

限流适配器

支持令牌桶,漏桶算法限流

使用第三方开源限流库

漏桶算法

go.uber.org/ratelimit

令牌桶算法

github.com/juju/ratelimit

demo

func main() {
	// 漏桶限流
	// b := ratelimit.NewLeakyBucket(5)
	// 令牌桶限流
	b := ratelimit.NewTokenBucket(5, 10)
	ad := ratelimit.NewAdapter(b)
	if ad.Allow() {
		fmt.Println("allow", time.Now())
	} else {
		fmt.Println("too many requests")
	}
}

About

限流适配器 适配令牌桶,漏桶算法限流。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages