Serving data from Context

  1. SendFile(filename string, destinationName string) error
  2. SendFileWithRate(src, destName string, limit float64, burst int) error

Usage

Force-Send a file to the client:

  1. func handler(ctx iris.Context) {
  2. src := "./files/first.zip"
  3. ctx.SendFile(src, "client.zip")
  4. }

Limit download speed to ~50Kb/s with a burst of 100KB:

  1. func handler(ctx iris.Context) {
  2. src := "./files/big.zip"
  3. // optionally, keep it empty to resolve the filename based on the "src".
  4. dest := ""
  5. limit := 50.0 * iris.KB
  6. burst := 100 * iris.KB
  7. ctx.SendFileWithRate(src, dest, limit, burst)
  8. }
  1. ServeContent(content io.ReadSeeker, filename string, modtime time.Time)
  2. ServeContentWithRate(content io.ReadSeeker, filename string, modtime time.Time, limit float64, burst int)
  3. ServeFile(filename string) error
  4. ServeFileWithRate(filename string, limit float64, burst int) error

Usage

  1. func handler(ctx iris.Context) {
  2. ctx.ServeFile("./public/main.js")
  3. }