An idiomatic Go implementation of Leaky bucket.

lbucket

Go Reference

lbucket is an idiomatic Go leaky bucket implementation.

The library make use of plain old Go stdlib; in other words, there are no third-party dependencies.

How to use

Package lbucket provides support for using leaky buckets on your app.

Creating a new Leaky bucket informing 3 as the bucket capacity and the frequency how the bucket leaks.

NewTickLeakyBucket(3, 1 * time.Second)

Calling Refill() you're add more volume in the bucket.

bucket := NewTickLeakyBucket(3, 1 * time.Second)
err := bucket.Refill()

Note: When the bucket capacity is reached a ErrBucketReachedCap will be returned until the bucket leaks once again. A simple errors.Is could be used in this scenario:

errors.Is(err, ErrBucketReachedCap)

To stop the bucket leaking you can call the Fix() method.

bucket.Fix()

Use Size() to get to current volume in the bucket.

bucket.Size()

Common use case(s)

API's rate limiter.

In this use you can read:

  • NewTickLeakyBucket() as How many requests per second it's gonna handle?
  • Refill() as Can I respond this request?
    • ErrBucketReachedCap as Reched the server limit
  • Fix() as From now on I'm no longer accepting requests
  • Size() as How many requests are in flight?

eg: NewTickLeakyBucket(3, 1 * time.Second) -> 3 requests / second.

Owner
Alex Rios
I like embedded systems and unusual integrations. Interested in testability/quality/explicitness of code.
Alex Rios
Similar Resources

Sliding window counters Redis rate limiting implementation for Golang

Sliding window counters Redis rate limiting implementation for Golang (Based on the Figma API rate limit algorithm)

Dec 21, 2022

Implementation for validating the NZ COVID Pass.

NZCP validator Validates NZCP passes according to https://nzcp.covid19.health.nz. Example See example_test.go and tests for more examples. func Exampl

Dec 20, 2021

Generic Free List implementation to reuse memory and avoid allocations

gofl GOFL provides a Generic Free List implementation for Go. Installation This

Oct 17, 2022

yaml-patch is a version of Evan Phoenix's json-patch, which is an implementation of JSON Patch, directly transposed to YAML

yaml-patch yaml-patch is a version of Evan Phoenix's json-patch, which is an implementation of JavaScript Object Notation (JSON) Patch, directly trans

Jan 15, 2022

A pure Golang implementation of Rockchip rknand vendor storage interface.

go-rkvendorstorage A pure Golang implementation of Rockchip rknand vendor storage interface. Usage package main import ( "fmt" "github.com/jamesits

Nov 8, 2022

Golang 1.18+ Generics implementation of Set methods

Golang Generics: Set A golang 1.18+ implementation of Set using Go generics Installation $ go get -u github.com/chrispappas/golang-generics-set Quick

Oct 26, 2022

A Golang blocking leaky-bucket rate limit implementation

Go rate limiter This package provides a Golang implementation of the leaky-bucket rate limit algorithm. This implementation refills the bucket based o

Jan 2, 2023

Ratelimit - This package provides a Golang implementation of the leaky-bucket rate limit algorithm

Go rate limiter This package provides a Golang implementation of the leaky-bucke

Jul 26, 2022

Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket

Features Resize upladed images to s3 bucket with given sizes, and uploades new images back to bucket Environment Variables IMAGE_SIZES - formax 200x20

Feb 2, 2022

Convert JPEG images from S3 bucket to BMP, GIF, PNG into another bucket

Convert JPEG images from S3 bucket to BMP, GIF, PNG into another bucket

aws-lambda Convert JPEG images from S3 bucket to BMP, GIF, PNG into another bucket Setup two buckets jpeg-images for source jpeg images converted-jpeg

Feb 13, 2022

concurrent map implementation using bucket list like a skip list.

Skip List Map in Golang Skip List Map is an ordered and concurrent map. this Map is goroutine safety for reading/updating/deleting, no-require locking

Oct 8, 2022

This service provides authenticated access to a static website hosted in an s3 bucket.

This service provides authenticated access to a static website hosted in an s3 bucket.

website-openid-proxy This service provides OpenID authenticated access to a static website hosted in an s3 bucket. It is designed to be a simple way t

Jan 19, 2022

Efficient token-bucket-based rate limiter package.

ratelimit -- import "github.com/juju/ratelimit" The ratelimit package provides an efficient token bucket implementation. See http://en.wikipedia.org/w

Dec 29, 2022

Bucket-ssh. A fuzzy ssh manager for managing and categorizing ssh connections.

Bucket-ssh. A fuzzy ssh manager for managing and categorizing ssh connections.

Bssh is an ssh bucket for categorizing and automating ssh connections. Also, with parallel command execution and connection checks(pings) over categories (namespaces).

Oct 25, 2022

Put a web archive (WARC) on an S3 bucket suitable for hosting with S3 Website Hosting.

warc-to-s3 This is a small Go application that consumes a WARC file ( using slyzrc/warc) and puts it on S3 suitable for serving with S3 Website Hostin

Jan 6, 2022

Empty an S3 bucket as fast as possible đź’¨

s3-destroyer Iteratively calls ListObjects, add objects keys to a buffer and calls DeleteObject in goroutines. Usage -access-key string s3 a

Dec 13, 2021

Go REST API - Bucket list - built with go-chi, Docker, and PostgreSQL

Go REST API - Bucket list - built with go-chi, Docker, and PostgreSQL Requirements Docker and Go golang-migrate/migrate Usage Clone the repository wit

Dec 14, 2021

Notify messages from gcs bucket objects to slack

Notify to Slack Notify message to slack from gcs storage file. Deploy $ gcloud functions deploy notify_to_slack \ --entry-point NotifyToSlack \

Oct 5, 2021

Minimal working example showing how to upload file to S3 bucket.

S3-upload-file Minimal working example showing how to upload file to S3 bucket. Usage Run the following command: docker-compose up A web server and a

Mar 2, 2022
go implementation of timsort

timsort timsort is a Go implementation of Tim Peters's mergesort sorting algorithm. For many input types it is 2-3 times faster than Go's built-in sor

Nov 7, 2022
Implementation of do255e and do255s in Go

Go Implementation of do255e and do255s This is a plain Go implementation of do255e and do255s. It is considered secure; all relevant functions should

Aug 15, 2022
Go implementation of the Heaven's Gate technique
Go implementation of the Heaven's Gate technique

gopherheaven is a Go implementation of the classic Heaven's Gate technique originally published by roy g biv on VX Heaven in 2009. gopherheaven can be used as an evasion technique to directly call 64-bit code from a 32-bit process.

Dec 20, 2022
Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation

stack Lightweight, Simple, Quick, Thread-Safe Golang Stack Implementation Purpose Provide a fast, thread safe, and generic Golang Stack API with minim

May 3, 2022
Optimal implementation of ordered maps for Golang - ie maps that remember the order in which keys were inserted.

Goland Ordered Maps Same as regular maps, but also remembers the order in which keys were inserted, akin to Python's collections.OrderedDicts. It offe

Jan 3, 2023
A faster RWLock primitive in Go, 2-3 times faster than RWMutex. A Go implementation of concurrency control algorithm in paper

Go Left Right Concurrency A Go implementation of the left-right concurrency control algorithm in paper <Left-Right - A Concurrency Control Technique w

Jan 6, 2023
Go implementation of the geodesic routines from GeographicLib
Go implementation of the geodesic routines from GeographicLib

geodesic This package is a Go implementation of the geodesic routines from GeographicLib. Features Pure Go implementation Distance calculations with n

Dec 23, 2022
go-logr implementation with pterm
go-logr implementation with pterm

plogr go-logr implementation with pterm Usage See examples Add more colors and levels By default, only level 0 (info) and level 1 (debug) are supporte

Dec 22, 2021
Reference go implementation of globaldce protocol

globaldce-go This is the reference implementation of the command line interface of globaldce coded in the go programming language. This project is sti

Nov 8, 2021
Go implementation Welford’s method for one-pass variance computation

Welford - Online method of calculating variance and standard deviation Go implementation Welford’s method for one-pass variance computation with D. H.

Jan 6, 2023