ratelimit

package module
v0.0.0-...-833ad8d Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 4 Imported by: 0

README

Rate Limit

Go Report Card

Library

Reverse Proxy

go get github.com/esnunes/ratelimit/cmd/rl-proxy

rl-proxy -h
# Rate Limit Proxy
#
# Usage:
#   rl-proxy [flags]
#
# Flags:
#   -a, --addr string   bind address ip:port (default ":8080")
#   -b, --burst int     maximum burst size of requests (default 1)
#   -h, --help          help for rl-proxy
#   -q, --queue int     maximum queued requests
#   -r, --rate float    requests per second (default 2)
  • Leaky Bucket algorithm;
  • Rate Limit based on target endpoint (considering connection latency);
  • Queue of connections when bucket limit reached;

TODO

  • Store and retrieve context values using functions;
  • Calculate rate limit value based on specific date (e.g. service startup time);
  • Cover with tests;
  • Create docs about library usage;
  • Create docs about proxy usage;
  • Add Prometheus metrics support;
    • Number of times a response status code occurred;
    • Number of no more slots error;
    • Number of requests in queue;
    • Number of requests running;
    • Histogram of requests response time;
    • General Go statistics;

License

ratelimit is licensed under the MIT license. Check the LICENSE file for details.

Author

Eduardo Nunes

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSlotsAvailable ...
	ErrNoSlotsAvailable = errors.New("no slots available")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Rate  time.Duration
	Burst int
	Queue int
}

Config ...

type Limiter

type Limiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Limiter ...

func NewLimiter

func NewLimiter(c Config) *Limiter

NewLimiter ...

func (*Limiter) Reserve

func (l *Limiter) Reserve() error

Reserve ...

func (*Limiter) Use

func (l *Limiter) Use()

Use ...

type Manager

type Manager struct {
	Config Config

	sync.Mutex
	// contains filtered or unexported fields
}

Manager ...

func (*Manager) Get

func (m *Manager) Get(b string) *Limiter

Get ...

type Queue

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

Queue ...

func NewQueue

func NewQueue() *Queue

NewQueue ...

func (*Queue) Add

func (q *Queue) Add() <-chan struct{}

Add ...

func (*Queue) Free

func (q *Queue) Free(n int)

Free ...

func (*Queue) Total

func (q *Queue) Total() int

Total ...

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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