forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
31 lines (24 loc) · 687 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)
}