增加地图广播限制速率

This commit is contained in:
1
2025-11-09 06:50:12 +00:00
parent de3fb29407
commit 742bcd8a3f
6 changed files with 39 additions and 11 deletions

View File

@@ -12,13 +12,11 @@ import (
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gfile"
"github.com/xiaoqidun/limit"
"golang.org/x/time/rate"
)
var (
limiter = limit.New()
Main = gcmd.Command{
Main = gcmd.Command{
Name: "main",
Usage: "main",
Brief: "start http server",
@@ -60,7 +58,7 @@ func Limiter(r *ghttp.Request) {
// 3. 为任意键 "some-key" 获取一个速率限制器
// - rate.Limit(2): 表示速率为 "每秒2个请求"
// - 2: 表示桶的容量 (Burst)允许瞬时处理2个请求
rateLimiter := limiter.Get(r.GetClientIp(), rate.Limit(10), 5)
rateLimiter := cool.Limiter.Get(r.GetClientIp(), rate.Limit(10), 5)
if !rateLimiter.Allow() {
r.Response.WriteStatusExit(429) // Return 429 Too Many Requests