func NewServerThrottleHook(max int) NamedHook {
	burst := max * 20 / 100
	if burst < 1 {
		burst = 1
	}
	timeout := time.Second / time.Duration(max)
	limiter := rate.NewLimiter(rate.Every(timeout), burst)
	return NamedHook{
		Name: "__server@throttle",
		Apply: func(w http.ResponseWriter, r *http.Request) bool {
			ctx, done := context.WithTimeout(context.Background(), timeout)
			err := limiter.Wait(ctx)
			done()
			if err != nil {
				log.Println("Exceed throughput:", err)
				w.Header().Set("Retry-After", time.Now().Add(timeout*3).Format(time.RFC3339))
				http.Error(w, http.StatusText(http.StatusTeapot), http.StatusTeapot)
				return false
			}
			return true
		},
	}
}
NewServerThrottleHook creates NamedHook with max throughput / per second.
NOTE: burst value is 20% of throttle
package hooks
import (
	"context"
	"log"
	"net/http"
	"time"
	"golang.org/x/time/rate"
)
type ServerHooks struct {
	RequestReceived *HookList
	RequestRouted *HookList
	ResponseReady *HookList
	ResponseAlways *HookList
}
func NewServerHooks() *ServerHooks {
	return &ServerHooks{
		RequestReceived: &HookList{},
		RequestRouted:   &HookList{},
		ResponseReady:   &HookList{},
		ResponseAlways:  &HookList{},
	}
}