Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 996 Bytes

README.md

File metadata and controls

43 lines (31 loc) · 996 Bytes

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,
}))