sentinel.go 535 B

1234567891011121314151617181920212223
  1. package middleware
  2. import (
  3. sentinelPlugin "github.com/alibaba/sentinel-golang/adapter/gin"
  4. "github.com/alibaba/sentinel-golang/core/system"
  5. "github.com/gin-gonic/gin"
  6. log "github.com/go-admin-team/go-admin-core/logger"
  7. )
  8. // Sentinel 限流
  9. func Sentinel() gin.HandlerFunc {
  10. if _, err := system.LoadRules([]*system.Rule{
  11. {
  12. MetricType: system.InboundQPS,
  13. TriggerCount: 200,
  14. Strategy: system.BBR,
  15. },
  16. }); err != nil {
  17. log.Fatalf("Unexpected error: %+v", err)
  18. }
  19. return sentinelPlugin.SentinelMiddleware()
  20. }