46
README.md
Normal file
46
README.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# echo-ratelimit
|
||||
|
||||
Small in-memory rate-limiting middleware for [Echo](https://github.com/labstack/echo), keyed by client IP.
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
go get github.com/labstack/echo/v4
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
ratelimit "git.carlpearson.net/cwpearson/echo-ratelimit"
|
||||
)
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
e.Use(ratelimit.Middleware(60, time.Minute))
|
||||
|
||||
e.GET("/", func(c echo.Context) error {
|
||||
return c.String(http.StatusOK, "ok")
|
||||
})
|
||||
|
||||
e.Logger.Fatal(e.Start(":8080"))
|
||||
}
|
||||
```
|
||||
|
||||
## Custom Configuration
|
||||
|
||||
```go
|
||||
e.Use(ratelimit.WithConfig(ratelimit.Config{
|
||||
Limit: 10,
|
||||
Window: time.Minute,
|
||||
}))
|
||||
```
|
||||
|
||||
Rate-limit headers are emitted by default.
|
||||
Reference in New Issue
Block a user