From 09d3b881da8e8b43426e3106e8fd40b3dbeaf0e4 Mon Sep 17 00:00:00 2001 From: Omer Zidkoni Date: Tue, 9 Apr 2024 09:31:09 +0300 Subject: [PATCH] CR --- http/filestream/filestream.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/http/filestream/filestream.go b/http/filestream/filestream.go index ce304aa..40f5402 100644 --- a/http/filestream/filestream.go +++ b/http/filestream/filestream.go @@ -62,17 +62,17 @@ type FileInfo struct { Path string } -func WriteFilesToStream(multipartWriter *multipart.Writer, filesList []*FileInfo) (err error) { - // Close finishes the multipart message and writes the trailing - // boundary end line to the output. - defer ioutils.Close(multipartWriter, &err) +func WriteFilesToStream(multipartWriter *multipart.Writer, filesList []*FileInfo) error { for _, file := range filesList { - if err = writeFile(multipartWriter, file); err != nil { + if err := writeFile(multipartWriter, file); err != nil { return writeErrPart(multipartWriter, file, err) } } - return nil + // Close finishes the multipart message and writes the trailing + // boundary end line to the output. + // We don't use defer for this because the multipart.Writer's Close() method writes regardless of whether there was an error or if writing hadn't started at all + return multipartWriter.Close() } func writeFile(multipartWriter *multipart.Writer, file *FileInfo) (err error) {