mirror of
https://github.com/dutchcoders/transfer.sh.git
synced 2024-12-11 21:30:19 +01:00
21 lines
527 B
Go
21 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))
|
|
}
|