Golang encoding/csv.Writer.Error() function example
package encoding/csv
Error reports any error that has occurred during a previous Write or Flush.
Golang encoding/csv.Writer.Error() function usage example
package main
import (
"encoding/csv"
"fmt"
"os"
)
func main() {
csvfile, err := os.Create("output.csv")
if err != nil {
fmt.Println("Error:", err)
return
}
defer csvfile.Close()
records := [][]string{{"item1", "value1"}, {"item2", "value2"}, {"item3", "value3"}}
writer := csv.NewWriter(csvfile)
for _, record := range records {
err := writer.Write(record) /// <------ here
if err != nil {
fmt.Println("Error:", err)
return
}
}
writer.Flush()
}
Reference :
Advertisement
Something interesting
Tutorials
+13.9k Golang : Get current time
+7.7k Golang : get the current working directory of a running program
+11.1k Golang : Read until certain character to break for loop
+11.7k Golang : Find age or leap age from date of birth example
+4k Detect if Google Analytics and Developer Media are loaded properly or not
+16.3k Golang :Trim white spaces from a string
+6.2k Golang : Process non-XML/JSON formatted ASCII text file example
+7.7k Golang : How to execute code at certain day, hour and minute?
+15.3k Golang : Delete certain files in a directory
+9.6k Golang : Quadratic example
+6.8k Golang : Calculate pivot points for a cross
+22.9k Golang : Calculate time different