2017-03-23 23:22:05 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2017-03-23 23:22:05 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2020-05-02 16:46:17 +02:00
|
|
|
app.Logger().SetLevel("debug")
|
2017-03-23 23:22:05 +01:00
|
|
|
|
2020-05-02 16:46:17 +02:00
|
|
|
app.Get("/", download)
|
|
|
|
app.Get("/download", downloadWithRateLimit)
|
2017-03-23 23:22:05 +01:00
|
|
|
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2017-03-23 23:22:05 +01:00
|
|
|
}
|
2020-05-02 16:46:17 +02:00
|
|
|
|
|
|
|
func download(ctx iris.Context) {
|
|
|
|
src := "./files/first.zip"
|
|
|
|
ctx.SendFile(src, "client.zip")
|
|
|
|
}
|
|
|
|
|
|
|
|
func downloadWithRateLimit(ctx iris.Context) {
|
|
|
|
// REPLACE THAT WITH A BIG LOCAL FILE OF YOUR OWN.
|
|
|
|
src := "./files/first.zip"
|
|
|
|
dest := "" /* optionally, keep it empty to resolve the filename based on the "src" */
|
|
|
|
|
|
|
|
// Limit download speed to ~50Kb/s with a burst of 100KB.
|
|
|
|
limit := 50.0 * iris.KB
|
|
|
|
burst := 100 * iris.KB
|
|
|
|
ctx.SendFileWithRate(src, dest, limit, burst)
|
|
|
|
}
|