Skip to content

Commit

Permalink
Make FileInfo a pointer (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored Mar 11, 2024
1 parent 23adf3a commit 13ecbc3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions http/filestream/filestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type FileInfo struct {
Path string
}

func WriteFilesToStream(multipartWriter *multipart.Writer, filesList []FileInfo) (err error) {
func WriteFilesToStream(multipartWriter *multipart.Writer, filesList []*FileInfo) (err error) {
for _, file := range filesList {
if err = writeFile(multipartWriter, file); err != nil {
return
Expand All @@ -65,7 +65,7 @@ func WriteFilesToStream(multipartWriter *multipart.Writer, filesList []FileInfo)
return multipartWriter.Close()
}

func writeFile(multipartWriter *multipart.Writer, file FileInfo) (err error) {
func writeFile(multipartWriter *multipart.Writer, file *FileInfo) (err error) {
fileReader, err := os.Open(file.Path)
defer ioutils.Close(fileReader, &err)
fileWriter, err := multipartWriter.CreateFormFile(FileType, file.Name)
Expand Down
6 changes: 3 additions & 3 deletions http/filestream/filestream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ var targetDir string
func TestWriteFilesToStreamAndReadFilesFromStream(t *testing.T) {
sourceDir := t.TempDir()
// Create 2 file to be transferred via our multipart stream
file1 := FileInfo{Name: "test1.txt", Path: filepath.Join(sourceDir, "test1.txt")}
file2 := FileInfo{Name: "test2.txt", Path: filepath.Join(sourceDir, "test2.txt")}
file1 := &FileInfo{Name: "test1.txt", Path: filepath.Join(sourceDir, "test1.txt")}
file2 := &FileInfo{Name: "test2.txt", Path: filepath.Join(sourceDir, "test2.txt")}
file1Content := []byte("test content1")
file2Content := []byte("test content2")
assert.NoError(t, os.WriteFile(file1.Path, file1Content, 0600))
Expand All @@ -25,7 +25,7 @@ func TestWriteFilesToStreamAndReadFilesFromStream(t *testing.T) {
// Create the multipart writer that will stream our files
body := &bytes.Buffer{}
multipartWriter := multipart.NewWriter(body)
assert.NoError(t, WriteFilesToStream(multipartWriter, []FileInfo{file1, file2}))
assert.NoError(t, WriteFilesToStream(multipartWriter, []*FileInfo{file1, file2}))

// Create local temp dir that will store our files
targetDir = t.TempDir()
Expand Down

0 comments on commit 13ecbc3

Please sign in to comment.