Reading CSV file in Go

Go now has a csv package for this. Its is encoding/csv. You can find the docs here:

There are a couple of good examples in the docs. Here is a helper method I created to read a csv file and returns its records.

package main

import (

func readCsvFile(filePath string) [][]string {
    f, err := os.Open(filePath)
    if err != nil {
        log.Fatal("Unable to read input file " + filePath, err)
    defer f.Close()

    csvReader := csv.NewReader(f)
    records, err := csvReader.ReadAll()
    if err != nil {
        log.Fatal("Unable to parse file as CSV for " + filePath, err)

    return records

func main() {
    records := readCsvFile("../tasks.csv")

Leave a Comment