Documentation
¶
Overview ¶
Example ¶
package main import ( "net/http" "time" "github.com/go-http-utils/ratelimit" ) func main() { 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, })) }
Index ¶
Examples ¶
Constants ¶
View Source
const Version = "0.3.0"
Version is this package's version number.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type GetIDFunc ¶
GetIDFunc represents a function that return an ID for each request. All requests which have the same ID will be regarded from one source and be ratelimited.
type Options ¶
type Options struct { // GetIDFunc represents a function that return an ID for each request. // All requests which have the same ID will be regarded from one source and // be ratelimited. GetID GetIDFunc // Ratelimit factor: only Count requests can pass through in Duration. // By default is 1 minute. Duration time.Duration // Ratelimit factor: only Count requests can pass through in Duration. // By default is 1000. Count int64 }
Options is the ratelimit middleware options.
Click to show internal directories.
Click to hide internal directories.