后端 Go+Gin:认证/CSRF/限流、板块、帖子、评论、点赞、通知、用户资料、置顶推荐;前端 Next.js 16:发帖/编辑/删除、搜索、分页、点赞、通知中心、设置;基础设施 docker-compose 与配置模板;添加 .gitignore 与专有许可证(保留所有权利)
21 lines
477 B
Go
21 lines
477 B
Go
package middleware
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/freefire/jiang13-bbs/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// RateLimitMiddleware 速率限制中间件
|
|
func RateLimitMiddleware(rl *service.RateLimiter, rateType string) gin.HandlerFunc {
|
|
return func(c *gin.Context) {
|
|
key := rateType + ":" + c.ClientIP()
|
|
if !rl.Allow(key) {
|
|
c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{"error": "请求过于频繁,请稍后再试"})
|
|
return
|
|
}
|
|
c.Next()
|
|
}
|
|
}
|