Created
April 29, 2022 02:52
-
-
Save mrkagelui/60fa9675a0a514ebb3661c42a2a5e6b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// run is the main logic of the service | |
func (s service) run(ctx context.Context, f filter) error { | |
pr, pw := io.Pipe() | |
r, err := s.ds.getData(ctx, f) | |
if err != nil { | |
return fmt.Errorf("querying: %v", err) | |
} | |
go writeRowsToCSV(r, pw) | |
if err := s.up.upload(ctx, pr); err != nil { | |
return fmt.Errorf("uploading: %v", err) | |
} | |
return nil | |
} | |
// ================csv conversion================ | |
func writeRowsToCSV(r *rows, w io.WriteCloser) error { | |
csvWriter := csv.NewWriter(w) | |
defer func() { | |
csvWriter.Flush() | |
w.Close() | |
}() | |
for r.next() { | |
// scan rows and write to csvWriter | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment