limiter

package
v0.0.0-...-f12b9c8 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatchedRule = errors.New("no matched rules")

Functions

This section is empty.

Types

type CounterService

type CounterService interface {
	Increment(ctx context.Context, key string, n uint32, ttl int64, syncRate int) (uint32, error)
	IncrementOnStorage(ctx context.Context, key string, n uint32, ttl int64) (uint32, error)
	Get(ctx context.Context, key string) (uint32, error)
	GetFromStorage(ctx context.Context, key string) (uint32, error)
}

type DescriptorLabel

type DescriptorLabel struct {
	Key   string `yaml:"key"`
	Value string `yaml:"value"`
}

type DomainRules

type DomainRules struct {
	Domain string  `yaml:"domain"`
	Rules  []*Rule `yaml:"rules"`
}

type Limit

type Limit struct {
	Requests uint32 `yaml:"requests"`
	Unit     string `yaml:"unit"`
}

type LimiterService

type LimiterService struct {
	// contains filtered or unexported fields
}

func NewLimiterService

func NewLimiterService(
	rulesService RulesService,
	counterService CounterService,
	logger *logrus.Logger,
	registerer prometheus.Registerer) *LimiterService

func (*LimiterService) ShouldRateLimit

func (l *LimiterService) ShouldRateLimit(ctx context.Context, req *pb.RateLimitRequest) (response *pb.RateLimitResponse, err error)

type Rule

type Rule struct {
	Name      string            `yaml:"name"`
	Labels    []DescriptorLabel `yaml:"labels"`
	Limit     Limit             `yaml:"limit"`
	SyncRate  int               `yaml:"syncRate"`
	InnerRank int
}

type RulesConfig

type RulesConfig struct {
	Domains []*DomainRules `yaml:"domains"`
}

type RulesService

type RulesService interface {
	GetRatelimitRule(domain string, requestDescriptor *rl.RateLimitDescriptor) (*Rule, error)
}

Jump to

Keyboard shortcuts

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