go.uber.org/ratelimit源码分析 go提供了一用来接口限流的包。其中"go.uber.org/ratelimit"包正是基于漏桶算法实现的。 使用方式: 通过ratelimit.New创建限流器对象,参数为每秒允许的请求数(RPS)。 使用Take()方法来获取限流许可,该方法会阻塞请求知道满足限速要求。 官方示例: import( "fmt" "time" "go.uber.org/ratelimit" ) funcmain(){ rl:=ratelimit.New(100)//每秒多少次 prev:=time.Now() fori:=0;i<10;i...

  KycJoT6rSfGR   21天前   53   0   0 Go
关注 更多

空空如也 ~ ~

粉丝 更多

空空如也 ~ ~