arithmetic_rate_limit_demo2

command
v0.0.0-...-29b1110 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

README


func DynamicLimitter(interval int, burst int) endpoint.Middleware {
	bucket := rate.NewLimiter(rate.Every(time.Second*time.Duration(interval)), burst)
	return func(next endpoint.Endpoint) endpoint.Endpoint {
		return func(ctx context.Context, request interface{}) (response interface{}, err error) {
			if !bucket.Allow() {
				return nil, ErrLimitExceed
			}
			return next(ctx, request)
		}
	}
}
endpoint := MakeArithmeticEndpoint(svc)
endpoint = DynamicLimitter(1, 3)(endpoint)

testEndp := MakeArithmeticEndpoint(svc)
testEndp = DynamicLimitter(1, 2)(testEndp)

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

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