An open API service indexing awesome lists of open source software.

https://github.com/go-http-utils/ratelimit

:no_bicycles:HTTP ratelimit middleware for Go
https://github.com/go-http-utils/ratelimit

Last synced: 5 months ago
JSON representation

:no_bicycles:HTTP ratelimit middleware for Go

Awesome Lists containing this project

README

          

# ratelimit
[![Build Status](https://travis-ci.org/go-http-utils/ratelimit.svg?branch=master)](https://travis-ci.org/go-http-utils/ratelimit)
[![Coverage Status](https://coveralls.io/repos/github/go-http-utils/ratelimit/badge.svg?branch=master)](https://coveralls.io/github/go-http-utils/ratelimit?branch=master)

HTTP ratelimit middleware for Go.

## Installation

```
go get -u github.com/go-http-utils/ratelimit
```

## Documentation

API documentation can be found here: https://godoc.org/github.com/go-http-utils/ratelimit

## Usage

```go
import (
"github.com/go-http-utils/ratelimit"
)
```

```go
getIDByReq := func(req *http.Request) string {
return req.RemoteAddr
}

m := http.NewServeMux()

m.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)

res.Write([]byte("Hello Worlkd"))
})

http.ListenAndServe(":8080", ratelimit.Handler(m, ratelimit.Options{
GetID: getIDByReq,
Duration: 1 * time.Second,
Count: 1000,
}))
```