cuttle

package
v0.0.0-...-7673ed1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BanControl

type BanControl struct {
	// Label of this control.
	Label string
}

BanControl bans all the request.

func NewBanControl

func NewBanControl(label string) *BanControl

NewBanControl return a new BanControl with the given label.

func (*BanControl) Acquire

func (c *BanControl) Acquire() bool

Acquire permission from BanControl. Permission is never granted.

func (*BanControl) Start

func (c *BanControl) Start()

Start running BanControl.

type LimitController

type LimitController interface {
	// Start the rate limit controller.
	Start()
	// Acquire permission to perform certain things.
	// The permission is granted according to the rate limit rule.
	Acquire() bool
}

LimitController defines behaviors of a rate limit control.

type NoopControl

type NoopControl struct {
	// Label of this control.
	Label string
}

NoopControl does not perform any rate limit.

func NewNoopControl

func NewNoopControl(label string) *NoopControl

NewNoopControl return a new NoopControl with the given label.

func (*NoopControl) Acquire

func (c *NoopControl) Acquire() bool

Acquire permission from NoopControl. Permission is granted immediately since it does not perform any rate limit.

func (*NoopControl) Start

func (c *NoopControl) Start()

Start running NoopControl.

type RPMControl

type RPMControl struct {
	// Label of this control.
	Label string
	// Rate holds the number of requests per minute.
	Rate int
	// contains filtered or unexported fields
}

RPMControl provides requests per minute rate limit control.

func NewRPMControl

func NewRPMControl(label string, rate int) *RPMControl

NewRPMControl return a new RPMControl with the given label and rate.

func (*RPMControl) Acquire

func (c *RPMControl) Acquire() bool

Acquire permission from RPMControl. Permission is granted at a rate of N requests per minute.

func (*RPMControl) Start

func (c *RPMControl) Start()

Start running RPMControl. A goroutine is launched to govern the rate limit of Acquire().

type RPSControl

type RPSControl struct {
	// Label of this control.
	Label string
	// Rate holds the number of requests per second.
	Rate int
	// contains filtered or unexported fields
}

RPSControl provides requests per second rate limit control.

func NewRPSControl

func NewRPSControl(label string, rate int) *RPSControl

NewRPSControl return a new RPSControl with the given label and rate.

func (*RPSControl) Acquire

func (c *RPSControl) Acquire() bool

Acquire permission from RPSControl. Permission is granted at a rate of N requests per second.

func (*RPSControl) Start

func (c *RPSControl) Start()

Start running RPSControl. A goroutine is launched to govern the rate limit of Acquire().

type Zone

type Zone struct {
	// Host specifies the URL host of the location(s).
	// It supports using wildcard '*' for matching part of the host name.
	// E.g. "*.github.com" matches both "www.github.com" and "api.github.com".
	Host string
	// Path specifies the URL path of the location(s).
	// It supports using wildcard '*' for matching part of the path.
	// E.g. "/*" matches both "/atom" and "/github".
	Path string

	// LimitBy specifies the rate limit subject of the location(s).
	// Rate limit can be performed by "host" or "path".
	LimitBy string
	// Shared specifies whether the rate limit is shared among all location(s) in the Zone.
	Shared bool

	// Control specifies which rate limit controller is used.
	Control string
	// Rate specifies the rate of the rate limit controller.
	Rate int
	// contains filtered or unexported fields
}

A Zone holds the settings and states of the rate limited location(s).

func NewZone

func NewZone(host string, path string, limitby string, shared bool, control string, rate int) *Zone

NewZone returns a new Zone given the configurations.

func (*Zone) GetController

func (z *Zone) GetController(host string, path string) LimitController

GetController returns the rate limit controller of a location.

func (*Zone) MatchHost

func (z *Zone) MatchHost(host string) bool

MatchHost determines whether the host name of a location belongs to the Zone.

func (*Zone) MatchPath

func (z *Zone) MatchPath(path string) bool

MatchPath determines whether the URL path of a location belongs to the Zone.

Jump to

Keyboard shortcuts

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