Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

throttle_test.go 443 B

1234567891011121314151617181920212223
  1. package ratelimit_test
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/VojtechVitek/ratelimit"
  6. )
  7. func ExampleThrottle() {
  8. middleware := ratelimit.Throttle(1)
  9. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  10. w.Write([]byte("working hard...\n\n"))
  11. if f, ok := w.(http.Flusher); ok {
  12. f.Flush()
  13. }
  14. time.Sleep(10 * time.Second)
  15. w.Write([]byte("done"))
  16. })
  17. http.ListenAndServe(":3333", middleware(handler))
  18. }