docs(微调文档): 对文档进行微调

This commit is contained in:
2025-09-23 21:11:39 +08:00
parent 6eeb13ca1d
commit 6cc84c0e49

View File

@@ -22,12 +22,10 @@ func main() {
limiter := limit.New() limiter := limit.New()
// 2. 确保在程序退出前优雅地停止后台任务,这非常重要 // 2. 确保在程序退出前优雅地停止后台任务,这非常重要
defer limiter.Stop() defer limiter.Stop()
// 3. 为任意键 "some-key" 获取一个速率限制器 // 3. 为任意键 "some-key" 获取一个速率限制器
// - rate.Limit(2): 表示速率为 "每秒2个请求" // - rate.Limit(2): 表示速率为 "每秒2个请求"
// - 2: 表示桶的容量 (Burst)允许瞬时处理2个请求 // - 2: 表示桶的容量 (Burst)允许瞬时处理2个请求
rateLimiter := limiter.Get("some-key", rate.Limit(2), 2) rateLimiter := limiter.Get("some-key", rate.Limit(2), 2)
// 4. 模拟3次连续的突发请求 // 4. 模拟3次连续的突发请求
// 由于速率和容量都为2只有前两次请求能立即成功 // 由于速率和容量都为2只有前两次请求能立即成功
for i := 0; i < 3; i++ { for i := 0; i < 3; i++ {