limiter

package
v0.0.0-...-40778be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IPMiddleware = zutil.Once(func() func(c *znet.Context) error {
	limit := limiter.NewRule()
	if MaxIPRequestPerSecond == 0 {
		MaxIPRequestPerSecond = 10
	}
	limit.AddRule(time.Second, MaxIPRequestPerSecond)
	tooManyRequestsTag := zerror.WrapTag(zerror.TagKind(ztype.ToString(http.StatusTooManyRequests)))(errors.New("Too many requests"))
	return func(c *znet.Context) error {
		if !limit.AllowVisitByIP(c.GetClientIP()) {
			return tooManyRequestsTag
		}
		c.Next()
		return nil
	}
})
View Source
var MaxIPRequestPerSecond = 10

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL