Skip to content

Commit

Permalink
Flush and close agents file
Browse files Browse the repository at this point in the history
  • Loading branch information
joecorall authored Nov 19, 2024
1 parent c16e5df commit deb1284
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions internal/handlers/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,17 @@ func TransformCsv(w http.ResponseWriter, r *http.Request) {
slog.Error("Failed to create file", "file", csvFile, "err", err)
os.Exit(1)
}
defer aFile.Close()

aWriter := csv.NewWriter(aFile)
defer aWriter.Flush()

for _, row := range linkedAgents {
if err := aWriter.Write(row); err != nil {
slog.Error("Failed to write record to CSV", "err", err)
http.Error(w, "Internal error", http.StatusInternalServerError)
return
}
}
aWriter.Flush()
aFile.Close()
}
w.Header().Set("Content-Type", "application/zip")
w.Header().Set("Content-Disposition", "attachment; filename=files.zip")
Expand Down

0 comments on commit deb1284

Please sign in to comment.