sqltocsv is a package to make it dead easy to turn arbitrary database query results (in the form of database/sql Rows) into CSV output.
Source and README at https://github.com/joho/sqltocsv
Write will write a CSV file to the writer passed in (with headers) based on whatever is in the sql.Rows you pass in.
WriteFile will write a CSV file to the file name specified (with headers) based on whatever is in the sql.Rows you pass in. It calls WriteCsvToWriter under the hood.
WriteString will return a string of the CSV. Don't use this unless you've got a small data set or a lot of memory
Converter does the actual work of converting the rows to CSV. There are a few settings you can override if you want to do some fancy stuff to your CSV.
New will return a Converter which will write your CSV however you like but will allow you to set a bunch of non-default behaivour like overriding headers or injecting a pre-processing step into your conversion
SetRowPreProcessor lets you specify a CsvPreprocessorFunc for this conversion
String returns the CSV as a string in an fmt package friendly way
Write writes the CSV to the Writer provided
WriteFile writes the CSV to the filename specified, return an error if problem
WriteString returns the CSV as a string and an error if something goes wrong
CsvPreprocessorFunc is a function type for preprocessing your CSV. It takes the columns after they've been munged into strings but before they've been passed into the CSV writer.
Return an outputRow of false if you want the row skipped otherwise return the processed Row slice as you want it written to the CSV.