Read a CSV file

Comma-Separated Value (CSV) file, it’s likely that applications like Excel export spreadsheets into CSV file or a custom application program encode it data into CSV format for you. I assumed you getting in UTF-8 encoded.

Instead of hard coding the filenames into the source code, filename will pass into the progam as parameters (arguments)

Public Dataset

Our example dataset (snip)

15-05-2020 00:00,4135001,1BY6WEcLGh8j5v7,0,0,0,6259559
15-05-2020 00:00,4135001,1IF53ai7Xc0U56Y,0,0,0,6183645
15-05-2020 00:00,4135001,3PZuoBAID5Wc2HD,0,0,0,6987759

First row, the header names, and from the second row our dataset separated by a comma each field match the header names

package main
import (
func main() {
    file, err := os.Open(os.Args[1])
    if err != nil {
    reader := csv.NewReader(file)
    records, _ := reader.ReadAll()
    // Dump the list