Documentation ¶
Overview ¶
Example ¶
r := iris.New() r.Use( SentinelMiddleware( // customize resource extractor if required // method_path by default WithResourceExtractor(func(ctx iris.Context) string { return ctx.GetHeader("X-Real-IP") }), // customize block fallback if required // abort with status 429 by default WithBlockFallback(func(ctx iris.Context) { ctx.StatusCode(400) ctx.JSON(map[string]interface{}{ "err": "too many request; the quota used up", "code": 10222, }) ctx.StopExecution() }), ), ) r.Get("/test", func(c iris.Context) {}) r.Run(iris.Addr(":9999"))
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SentinelMiddleware ¶
func SentinelMiddleware(opts ...Option) iris.Handler
Types ¶
type Option ¶
type Option func(*options)
func WithBlockFallback ¶
func WithBlockFallback(fn func(ctx iris.Context)) Option
WithBlockFallback sets the fallback handler when requests are blocked.
func WithResourceExtractor ¶
WithResourceExtractor sets the resource extractor of the web requests.
Click to show internal directories.
Click to hide internal directories.