Loading

摘要: 主要思路: 1.创建channel,通过定时器定时往channel中写入令牌,返回令牌桶本身(channel); 2.判断请求是否可以拿到令牌; package main import ( "context" "fmt" "time" ) func getBucket(capacityPs, max 阅读全文
posted @ 2021-12-09 16:08 集君 阅读(260) 评论(0) 推荐(0)
摘要: 参考: https://www.freeaihub.com/post/105431.html http://hustcat.github.io/rate-limit-example-in-go/ 令牌桶模型 官方实现:golang.org/x/time/rate 主要方法为: type Limite 阅读全文
posted @ 2021-12-09 14:32 集君 阅读(202) 评论(0) 推荐(0)