A rate limiter for the gin framework

GinRateLimit

GinRateLimit is a rate limiter for the gin framework. By default, it can only store rate limit info in memory. If you want to store it somewhere else like redis you can make your own store or use third party stores, similar to how express-rate-limit does it. The library is new so there are no third party stores yet, sso I would appreciate if someone could make one.

Install

go get github.com/Nebulizer1213/GinRateLimit

Basic Setup

package main

import (
	"github.com/gin-gonic/gin"
	"github.com/Nebulizer1213/GinRateLimit"
)

func keyFunc(c *gin.Context) string {
	return c.ClientIP()
}

func errorHandler(c *gin.Context) {
	c.String(429, "Too many requests")
}

func main() {
	server := gin.Default()
	// This makes it so each ip can only make 5 requests per second
	store := GinRateLimit.InMemoryStore(1, 5)
	mw := GinRateLimit.RateLimiter(keyFunc, errorHandler, &store)
	server.GET("/", mw, func(c *gin.Context) {
		c.String(200, "Hello World")
	})
}

Custom Store Example

package main

type CustomStore struct {
}

// Your store must have a method called Limit that takes a key and returns a bool
func (s *CustomStore) Limit(key string) bool {
	// Do your rate limit logic, and return true if the user went over the rate limit, otherwise return false
	if UserWentOverLimit {
		return true
	}
	return false
}
Similar Resources

Gcra - Package gcra implements the generic cell rate algorithm

gcra Package gcra implements the generic cell rate algorithm (GCRA). Example opt

Jan 23, 2022

A Caddy v2 extension to apply rate-limiting for HTTP requests

ratelimit A Caddy v2 extension to apply rate-limiting for HTTP requests. Installation $ xcaddy build --with github.com/owlwang/caddy-ratelimit Caddyfi

Jan 28, 2022

Dhrate - Quickly check Dockerhub rate (limit) as an unauthenticated user

Dhrate - Quickly check Dockerhub rate (limit) as an unauthenticated user

Dockerhub Rate A small Go program that returns the Dockerhub rate of an unauthen

Feb 7, 2022

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

A sample web API in GO (with GIn) under a domain driven architecture.

Golang Sample API Domain Driven Design Pattern 1. About This sample project presents a custom made domain driven API architecture in Golang using the

Jan 10, 2022

A basic sample web-services application using Go and Gin.

Sample application for Go Web Services A very basic web-services application built with go-lang and the Gin Web Framework. Based on https://github.com

Jan 13, 2022

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。

🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。

English | 🇨🇳 中文 📖 Introduction gnet is an event-driven networking framework that is fast and lightweight. It makes direct epoll and kqueue syscalls

Jan 2, 2023

An experimental go FTP server framework

graval Go FTP server framework. By providing a simple driver class that responds to a handful of methods you can have a complete FTP server. Some samp

Sep 27, 2022

NFF-Go -Network Function Framework for GO (former YANFF)

Network Function Framework for Go (former YANFF) Wonderful news : we are now supporting AF_XDP and supporting(almost) getting packets directly from Li

Dec 28, 2022
Related tags
A rate limiter for the gin framework

GinRateLimit GinRateLimit is a rate limiter for the gin framework. By default, it can only store rate limit info in memory. If you want to store it so

Dec 22, 2021
Common rate-limiter implementations

Overview An example Rate Limiter library used to control the rate that events occur, but these can also be used as thresholds that should replenish ov

Dec 1, 2021
A rate limiter for Golang, with ETCD data bindings

Go Rate limiter This package allows us to have a distributed rate limiter, using Redis as a central counter. The limits that are set are only "soft" l

Dec 9, 2021
Go rate limiter used to ensure a minimum duration between executions.

Ratelimiter Rate limiter used to ensure a minimum duration between executions. Additionally supports the optional limit of max queue size. This can be

Jul 14, 2022
Pacemaker - Rate limit library. Currently implemented rate limits are

PaceMaker Rate limit library. Currently implemented rate limits are Fixed window

Nov 5, 2022
Simple-request-limiter - Example of limiting API requests using standard Go library

Route: http://localhost:8080/urls example of body in POST request that was used:

Feb 2, 2022
Golang implementation of Sliding Window Algorithm for distributed rate limiting.
Golang implementation of Sliding Window Algorithm for distributed rate limiting.

slidingwindow Golang implementation of Sliding Window Algorithm for distributed rate limiting. Installation $ go get -u github.com/RussellLuo/slidingw

Dec 27, 2022
HTTP rate limiting module for Caddy 2

This module implements both internal and distributed HTTP rate limiting. Requests can be rejected after a specified rate limit is hit.

Jan 3, 2023
Light weight http rate limiting proxy

Introduction Light weight http rate limiting proxy. The proxy will perform rate limiting based on the rules defined in the configuration file. If no r

Dec 23, 2022
A little ping pong service that implements rate limiting with golang

Fred the Guardian Introduction Writing a little ping pong service that implements rate limiting with the programming language golang. Requirements Web

Jan 2, 2022