Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

22 righe
527 B

  1. package ratelimit_test
  2. import (
  3. "net/http"
  4. "time"
  5. "github.com/VojtechVitek/ratelimit"
  6. "github.com/VojtechVitek/ratelimit/memory"
  7. )
  8. // Watch the download speed with
  9. // wget http://localhost:3333/file -q --show-progress
  10. func ExampleDownloadSpeed() {
  11. middleware := ratelimit.DownloadSpeed(ratelimit.IP).Rate(1024, time.Second).LimitBy(memory.New())
  12. handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
  13. http.ServeFile(w, r, "/dev/random")
  14. })
  15. http.ListenAndServe(":3333", middleware(handler))
  16. }