Skip to content

17twenty/gorillimiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gorillimiter

What is this

Gorilla Mux compatible rate limiter middleware with some opinions

Thanks to https://github.com/hashicorp/golang-lru and https://www.alexedwards.net/blog/how-to-rate-limit-http-requests for inspiration.

Usage

mux := http.NewServeMux()
mux.HandleFunc("/", yourHandler)
...
log.Println("Listening on :5000...")
// Attach listener here with prefs for window
http.ListenAndServe(":5000", gorillimiter.Limiter(mux, 10, time.Second))

Demo

$ cd src/demo
$ go build && ./demo
2020/03/31 16:57:53 Listening on :5000...
... # At this point, smash it with curl -i localhost:5000
2020/03/31 16:54:01 User [::1] is over rate limit, denying for now, current count [13]
2020/03/31 16:54:01 User [::1] is over rate limit, denying for now, current count [14]
2020/03/31 16:54:01 User [::1] is over rate limit, denying for now, current count [15]
2020/03/31 16:54:01 User [::1] is over rate limit, denying for now, current count [16]
2020/03/31 16:54:01 User [::1] is over rate limit, denying for now, current count [17]
2020/03/31 16:54:01 User [::1] is over rate limit, denying for now, current count [18]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages