Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
limiter
✓ github.com/ulule/limiter/v3
Rate limit HTTP requests using in-memory store
package main
import (
"net/http"
"github.com/ulule/limiter/v3"
"github.com/ulule/limiter/v3/drivers/store/memory"
)
func main() {
rate := limiter.Rate{
Period: 1 * time.Second,
Limit: 10,
}
store := memory.NewStore()
instance := limiter.New(store, rate)
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
ctx, err := instance.Get(r.Context(), r.RemoteAddr)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if ctx.Reached {
http.Error(w, "Rate limit exceeded", http.StatusTooManyRequests)
return
}
w.Write([]byte("OK"))
})
http.ListenAndServe(":8080", nil)
}
Debug
Known issues
No known issues recorded.
Upgrade
Version history
3.11.2latest on pkg.go.dev
Audit
Dependencies
No dependency data recorded yet.