You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

22 lines
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. }