mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 10:41:03 +01:00
dbd6fcd2d7
as requested at: https://github.com/kataras/iris/issues/1493 Former-commit-id: 7783fde04b4247056e6309e7ec1df27f027dc655
32 lines
687 B
Go
32 lines
687 B
Go
package main
|
|
|
|
import (
|
|
"github.com/kataras/iris/v12"
|
|
)
|
|
|
|
func main() {
|
|
app := iris.New()
|
|
app.Logger().SetLevel("debug")
|
|
|
|
app.Get("/", download)
|
|
app.Get("/download", downloadWithRateLimit)
|
|
|
|
app.Listen(":8080")
|
|
}
|
|
|
|
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)
|
|
}
|