支持限流,200QPS
This commit is contained in:
1 parent
4741137c9a
commit
1e8544f1ce
4 files changed
+422
-8
No files matched your search
@@ -0,0 +1,23 @@
|
||||
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()
|
||||
}
|
||||
Reference in new issue
Block a user