Exporters now need to return error. This is done because of simple error logging.

This commit is contained in:
Musab Gültekin
2021-04-14 09:30:17 +03:00
parent e3d79e2574
commit 46c4db6b1a
4 changed files with 31 additions and 21 deletions

View File

@ -17,13 +17,12 @@ type CSV struct {
}
// Export exports response data as CSV streaming file
func (e *CSV) Export(exports chan interface{}) {
func (e *CSV) Export(exports chan interface{}) error {
// Create or append file
file, err := os.OpenFile(internal.DefaultString(e.FileName, "out.csv"), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
internal.Logger.Printf("Output file creation error: %v\n", err)
return
return fmt.Errorf("output file creation error: %w", err)
}
defer file.Close()
@ -53,4 +52,6 @@ func (e *CSV) Export(exports chan interface{}) {
}
}
writer.Flush()
return nil
}