Documentation ¶
Overview ¶
This package provides Sentinel middleware for Gear.
Users may register SentinelMiddleware to the Gear router, like.
import ( sentinelPlugear "github.com/sentinel-group/sentinel-go-adapters/gear" "github.com/teambition/gear" ) r := gear.NewRouter() r.Use(sentinelPlugear.SentinelMiddleware())
The plugear extracts "HttpMethod:Router" as the resource name by default (e.g. GET:/foo/:id). Users may provide customized resource name extractor when creating new SentinelMiddleware (via options).
Fallback logic: the plugear will return "429 Too Many Requests" status code if current request is blocked by Sentinel rules. Users may also provide customized fallback logic via WithBlockFallback(handler) options.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SentinelMiddleware ¶
func SentinelMiddleware(opts ...Option) gear.Middleware
SentinelMiddleware returns new gear.Middleware Default resource name is {method}:{path}, such as "GET:/api/users/:id" Default block fallback is returning 429 code Define your own behavior by setting options
Types ¶
type Option ¶
type Option func(*options)
func WithBlockFallback ¶
WithBlockFallback sets the fallback handler when requests are blocked.