Skip to content

go-http-utils/ratelimit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ratelimit

Build Status Coverage Status

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

import (
  "github.com/go-http-utils/ratelimit"
)
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,
}))

Releases

No releases published

Packages

No packages published