rkginlimit

package
v1.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package rkginlimit is a middleware of gin framework for adding rate limit in RPC response

Index

Constants

View Source
const (
	TokenBucket   = "tokenBucket"
	LeakyBucket   = "leakyBucket"
	DefaultLimit  = 1000000
	GlobalLimiter = "rk-limiter"
)

Variables

This section is empty.

Functions

func Interceptor

func Interceptor(opts ...Option) gin.HandlerFunc

Interceptor Add rate limit interceptors.

Types

type Limiter

type Limiter func(ctx *gin.Context) error

User could implement

type NoopLimiter

type NoopLimiter struct{}

NoopLimiter will do nothing

func (*NoopLimiter) Limit

func (l *NoopLimiter) Limit(*gin.Context) error

Limit will do nothing

type Option

type Option func(*optionSet)

Option if for middleware options while creating middleware

func WithAlgorithm

func WithAlgorithm(algo string) Option

WithAlgorithm provide algorithm of rate limit. - tokenBucket - leakyBucket

func WithEntryNameAndType

func WithEntryNameAndType(entryName, entryType string) Option

WithEntryNameAndType provide entry name and entry type.

func WithGlobalLimiter

func WithGlobalLimiter(l Limiter) Option

WithGlobalLimiter provide user defined Limiter.

func WithLimiterByPath

func WithLimiterByPath(path string, l Limiter) Option

WithLimiterByPath provide user defined Limiter by method.

func WithReqPerSec

func WithReqPerSec(reqPerSec int) Option

WithReqPerSec Provide request per second.

func WithReqPerSecByPath

func WithReqPerSecByPath(path string, reqPerSec int) Option

WithReqPerSecByPath Provide request per second by method.

type ZeroRateLimiter

type ZeroRateLimiter struct{}

ZeroRateLimiter will block requests.

func (*ZeroRateLimiter) Limit

func (l *ZeroRateLimiter) Limit(*gin.Context) error

Limit will block request and return error

Jump to

Keyboard shortcuts

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