You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This (taken from example) adds the chain to DefaultServeMux for a path. You can use a ServeMux, or you can write your own handler that processes the path.
package main
import (
"net/http"
"time"
"github.com/throttled/throttled"
"github.com/justinas/alice"
"github.com/justinas/nosurf"
)`
func timeoutHandler(h http.Handler) http.Handler {
return http.TimeoutHandler(h, 1*time.Second, "timed out")
}
func myApp(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello world!"))
}
func main() {
th := throttled.Interval(throttled.PerSec(10), 1, &throttled.VaryBy{Path: true}, 50)
myHandler := http.HandlerFunc(myApp)
chain := alice.New(th.Throttle, timeoutHandler, nosurf.NewPure).Then(myHandler)
http.Handle("/", chain) // Path "/" registers chain to DefaultServeMux for all unregistered paths
http.ListenAndServe(":8000", nil) // nil means to use DefaultServeMux
}
How would you use this if you want to use a middle per route/path?
The text was updated successfully, but these errors were encountered: