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
+29.5k Golang : How to create new XML file ?
+12.3k Golang : Validate email address
+10.5k Golang : Create matrix with Gonum Matrix package example
+26.8k Golang : Find files by extension
+29.1k Golang : Get first few and last few characters from string
+7.8k Golang : Example of how to detect which type of script a word belongs to
+4.7k Adding Skype actions such as call and chat into web page examples
+11.2k Golang : Calculate Relative Strength Index(RSI) example
+13.6k Golang : Query string with space symbol %20 in between
+6.7k Golang : When to use make or new?
+7.6k Golang : Set horizontal, vertical scroll bars policies and disable interaction on Qt image
+4.6k MariaDB/MySQL : How to get version information