mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 18:20:50 +00:00
24 lines
505 B
Go
24 lines
505 B
Go
package middleware
|
|
|
|
import (
|
|
sentinelPlugin "github.com/alibaba/sentinel-golang/adapter/gin"
|
|
"github.com/alibaba/sentinel-golang/core/system"
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"go-admin/common/log"
|
|
)
|
|
|
|
// Sentinel 限流
|
|
func Sentinel() gin.HandlerFunc {
|
|
if _, err := system.LoadRules([]*system.Rule{
|
|
{
|
|
MetricType: system.InboundQPS,
|
|
TriggerCount: 200,
|
|
Strategy: system.BBR,
|
|
},
|
|
}); err != nil {
|
|
log.Fatalf("Unexpected error: %+v", err)
|
|
}
|
|
return sentinelPlugin.SentinelMiddleware()
|
|
}
|