GitXplorerGitXplorer
d

tollbooth_echo

public
22 stars
8 forks
2 issues

Commits

List of commits on branch master.
Verified
8e558c99076d6e1c915138748a30aa98002ad830

updated to /tollbooth/v7 and echo/v4, added test script, updated README (#6)

AAndriyKalashnykov committed 2 years ago
Verified
6a73caa03064d2d9cf98a2173b3205835e9ecf53

Merge pull request #5 from nelsonkti/master

ddidip committed 4 years ago
Unverified
de836358b29dc70a0fafe9fb4c58cebeb74ad514

tollbooth version upgrade changed NewLimiter

nnelsonkti committed 4 years ago
Verified
5adbfff23d88855323598a4e29ad4dafd12e571d

Merge pull request #3 from mbulatova/update-echo-v4

ddidip committed 5 years ago
Unverified
c47713cd0c2a5ae97f24ca64c812a395387b89ca

Update to use echo/v4

jjust-musha committed 5 years ago
Unverified
0a1fd25de5b3312b5a82c9dfbf41d3b7ae4dd4cb

Don’t vendor.

ddidip committed 7 years ago

README

The README file for this repository.

tollbooth_echo

Echo middleware for rate limiting HTTP requests.

Five Minutes Tutorial

Open terminal

cd test
go run main.go

in another terminal

cd scripts
./test.sh
package main

import (
	"github.com/didip/tollbooth/v7"
	"github.com/didip/tollbooth_echo"
	"github.com/labstack/echo/v4"
	"net/http"
)

func main() {
	e := echo.New()

	// Create a limiter struct.
	limiter := tollbooth.NewLimiter(1, nil)
	// or
	// var tbOptions  limiter.ExpirableOptions
	// tbOptions.DefaultExpirationTTL = time.Second
	// tbOptions.ExpireJobInterval = 0
	// limiter := tollbooth.NewLimiter(1, &tbOptions)

	e.GET("/", echo.HandlerFunc(func(c echo.Context) error {
		return echo.NewHTTPError(http.StatusOK, "OK")
	}), tollbooth_echo.LimitHandler(limiter))

	e.Start(":4444")
}