rlutils

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2024 License: MIT Imports: 9 Imported by: 0

README

rl Go Reference build Coverage Code to Test Ratio Test Execution Time

This is a repository for collecting rate limiters in rl.

Usage


h := rlutils.NewHostLimiter(
    reqLimit,
    windowLen,
    targetExtensions,
    onRequestLimit,
)

handler := rl.New(h)

Documentation

Index

Constants

View Source
const (
	RemoteAddrKey = "remote_addr"
	HostKey       = "host"
)
View Source
const ContextCountryKey key = iota

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseLimiter

type BaseLimiter struct {
	rl.Counter
	// contains filtered or unexported fields
}

func NewBaseLimiter

func NewBaseLimiter(
	reqLimit int,
	windowLen time.Duration,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setters ...Option,
) BaseLimiter

func (*BaseLimiter) IsTargetRequest

func (l *BaseLimiter) IsTargetRequest(r *http.Request) bool

func (*BaseLimiter) Name

func (l *BaseLimiter) Name() string

func (*BaseLimiter) ShouldSetXRateLimitHeaders

func (l *BaseLimiter) ShouldSetXRateLimitHeaders(r *rl.Context) bool

type CountryLimiter

type CountryLimiter struct {
	BaseLimiter
	// contains filtered or unexported fields
}

func NewCountryLimiter

func NewCountryLimiter(
	dbPath string,
	countries []string,
	skipCountries []string,
	reqLimit int,
	windowLen time.Duration,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setter ...Option,
) (*CountryLimiter, error)

国別のリクエスト数を制限する 制限単位はIPアドレス

func (*CountryLimiter) Name

func (l *CountryLimiter) Name() string

func (*CountryLimiter) OnRequestLimit

func (l *CountryLimiter) OnRequestLimit(r *rl.Context) http.HandlerFunc

func (*CountryLimiter) Rule

func (l *CountryLimiter) Rule(r *http.Request) (*rl.Rule, error)

type GetParameterLimiter

type GetParameterLimiter struct {
	BaseLimiter
	// contains filtered or unexported fields
}

func NewGetParameterLimiter

func NewGetParameterLimiter(
	getParameters map[string]string,
	reqLimit int,
	windowLen time.Duration,
	key string,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setter ...Option,
) (*GetParameterLimiter, error)

Getパラメーターごとにリクエスト数を制限する 制限単位はホスト名とGetパラメーター

func (*GetParameterLimiter) Name

func (l *GetParameterLimiter) Name() string

func (*GetParameterLimiter) OnRequestLimit

func (l *GetParameterLimiter) OnRequestLimit(r *rl.Context) http.HandlerFunc

func (*GetParameterLimiter) Rule

func (l *GetParameterLimiter) Rule(r *http.Request) (*rl.Rule, error)

type HostLimiter

type HostLimiter struct {
	BaseLimiter
}

func NewHostLimiter

func NewHostLimiter(
	reqLimit int,
	windowLen time.Duration,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setter ...Option,
) *HostLimiter

ホストごとにリクエスト数を制限する 制限単位はホスト名

func (*HostLimiter) Name

func (l *HostLimiter) Name() string

func (*HostLimiter) OnRequestLimit

func (l *HostLimiter) OnRequestLimit(r *rl.Context) http.HandlerFunc

func (*HostLimiter) Rule

func (l *HostLimiter) Rule(r *http.Request) (*rl.Rule, error)

type IPLimiter

type IPLimiter struct {
	BaseLimiter
}

func NewIPLimiter

func NewIPLimiter(
	reqLimit int,
	windowLen time.Duration,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setter ...Option,
) *IPLimiter

ホストごとにリクエスト数を制限する 制限単位はIP

func (*IPLimiter) Name

func (l *IPLimiter) Name() string

func (*IPLimiter) OnRequestLimit

func (l *IPLimiter) OnRequestLimit(r *rl.Context) http.HandlerFunc

func (*IPLimiter) Rule

func (l *IPLimiter) Rule(r *http.Request) (*rl.Rule, error)

type Option added in v0.0.8

type Option func(*Options)

func IgnorePathContains added in v0.0.8

func IgnorePathContains(ignorePathContains []string) Option

func IgnorePathPrefixes added in v0.0.8

func IgnorePathPrefixes(ignorePathPrefixes []string) Option

func IgnorePathSuffixes added in v0.0.8

func IgnorePathSuffixes(ignorePathSuffixes []string) Option

func TargetConditionFunc added in v0.0.9

func TargetConditionFunc(f func(r *http.Request) bool) Option

func TargetExtensions added in v0.0.8

func TargetExtensions(targetExtensions []string) Option

func TargetMethods added in v0.0.8

func TargetMethods(targetMethods []string) Option

type Options added in v0.0.8

type Options struct {
	TargetExtensions     map[string]struct{}
	TargetMethods        map[string]struct{}
	IgnorePathContains   []string
	IgnorePathPrefixes   []string
	IgnorePathSuffixes   []string
	TargetConditionFuncs []func(r *http.Request) bool
}

type RequestPathLimiter

type RequestPathLimiter struct {
	BaseLimiter
	// contains filtered or unexported fields
}

func NewRequestPathLimiter

func NewRequestPathLimiter(
	requestPathContains []string,
	requestPathPrefixes []string,
	requestPathSuffixes []string,
	reqLimit int,
	windowLen time.Duration,
	key string,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setter ...Option,

) (*RequestPathLimiter, error)

リクエストパスごとにリクエスト数を制限する 制限単位はホスト名 + リクエストパス

func (*RequestPathLimiter) Name

func (l *RequestPathLimiter) Name() string

func (*RequestPathLimiter) OnRequestLimit

func (l *RequestPathLimiter) OnRequestLimit(r *rl.Context) http.HandlerFunc

func (*RequestPathLimiter) Rule

func (l *RequestPathLimiter) Rule(r *http.Request) (*rl.Rule, error)

type UserAgentLimiter

type UserAgentLimiter struct {
	BaseLimiter
	// contains filtered or unexported fields
}

func NewUserAgentLimiter

func NewUserAgentLimiter(
	userAgents []string,
	reqLimit int,
	windowLen time.Duration,
	onRequestLimit func(*rl.Context, string) http.HandlerFunc,
	setter ...Option,
) *UserAgentLimiter

ユーザーエージェントごとにリクエスト数を制限する 制限単位はユーザーエージェント

func (*UserAgentLimiter) Name

func (l *UserAgentLimiter) Name() string

func (*UserAgentLimiter) OnRequestLimit

func (l *UserAgentLimiter) OnRequestLimit(r *rl.Context) http.HandlerFunc

func (*UserAgentLimiter) Rule

func (l *UserAgentLimiter) Rule(r *http.Request) (*rl.Rule, error)

Jump to

Keyboard shortcuts

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