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:
committed by
Bo-Yi Wu
parent
5636afe02d
commit
bf7803815b
10
context.go
10
context.go
@ -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)
|
||||
|
Reference in New Issue
Block a user