1
0
mirror of https://github.com/dutchcoders/transfer.sh.git synced 2020-11-18 19:53:40 -08:00
2017-03-28 17:26:32 +02:00

22 lines
527 B
Go

package ratelimit_test
import (
"net/http"
"time"
"github.com/VojtechVitek/ratelimit"
"github.com/VojtechVitek/ratelimit/memory"
)
// Watch the download speed with
// wget http://localhost:3333/file -q --show-progress
func ExampleDownloadSpeed() {
middleware := ratelimit.DownloadSpeed(ratelimit.IP).Rate(1024, time.Second).LimitBy(memory.New())
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "/dev/random")
})
http.ListenAndServe(":3333", middleware(handler))
}