No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

22 líneas
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. }