Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

added detailed comment for render.Download() #2333

Merged
merged 1 commit into from
Sep 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions render/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ func (r downloadRenderer) Render(w io.Writer, d Data) error {
//
// Content-Type is set using mime#TypeByExtension with the filename's extension. Content-Type will default to
// application/octet-stream if using a filename with an unknown extension.
//
// Note: the purpose of this function is not serving static files but to support
// downloading of dynamically genrated data as a file. For example, you can use
// this function when you implement CSV file download feature for the result of
// a database query.
//
// Do not use this function for large io.Reader. It could cause out of memory if
// the size of io.Reader is too big.
func Download(ctx context.Context, name string, r io.Reader) Renderer {
return downloadRenderer{
ctx: ctx,
Expand All @@ -70,6 +78,14 @@ func Download(ctx context.Context, name string, r io.Reader) Renderer {
//
// Content-Type is set using mime#TypeByExtension with the filename's extension. Content-Type will default to
// application/octet-stream if using a filename with an unknown extension.
//
// Note: the purpose of this method is not serving static files but to support
// downloading of dynamically genrated data as a file. For example, you can use
// this method when you implement CSV file download feature for the result of
// a database query.
//
// Do not use this method for large io.Reader. It could cause out of memory if
// the size of io.Reader is too big.
func (e *Engine) Download(ctx context.Context, name string, r io.Reader) Renderer {
return Download(ctx, name, r)
}
Expand Down