Serve easily dynamic files with DataFromReader context method (#1304)

* Add DataFromReader context method

* Replace fmt by strconv.FormatInt

* Add pull request link to README
This commit is contained in:
Jean-Christophe Lebreton
2018-05-12 05:00:42 +02:00
committed by Bo-Yi Wu
parent 5636afe02d
commit bf7803815b
6 changed files with 116 additions and 0 deletions

View File

@ -741,6 +741,16 @@ func (c *Context) Data(code int, contentType string, data []byte) {
})
}
// DataFromReader writes the specified reader into the body stream and updates the HTTP code.
func (c *Context) DataFromReader(code int, contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string) {
c.Render(code, render.Reader{
Headers: extraHeaders,
ContentType: contentType,
ContentLength: contentLength,
Reader: reader,
})
}
// File writes the specified file into the body stream in a efficient way.
func (c *Context) File(filepath string) {
http.ServeFile(c.Writer, c.Request, filepath)