Gin Toll

A tollbooth middleware for Gin

I’m what could be described as a heavy Gin user. I’ve tried (and failed) to kick the stuff many times but for me, the process of creating a web API is made all the more enjoyable because of it. And Echo.

For those who’ve exposed their Go code on the internet before, you’ll be keenly aware of the choice of available rate-limiters. I’ve done the rounds too and, being lazy, hoped to find something that’d plug straight into Gin.


To keep my API definition as simple as possibly, I created a very simple tollbooth wrapper, which works as a middleware for Gin. Here’s how to limit requests to 1 per second:

Grab it from github:

$ go get

Import it into your code:

import ""

Use the LimitMiddleware method to create a Gin middleware:

router := gin.Default()
router.Use(gintoll.LimitMiddleware(tollbooth.NewLimiter(1, time.Second)))
router.GET("/get", func(c *gin.Context) { c.String(http.StatusOK, "Now we know...") })

Originally published at

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.