The package provides a simple typed parser for csv/dsv files.
go get github.com/tomaspavlic/csv
import (
// import the package"github.com/tomaspavlic/csv"
)Only exportable fields are considered. The name of the field is used unless Tag csv is used to specify actual name of a column in CSV.
// define struct typetypeTaxablestruct {
IndexintDescriptionstring`csv:"Item"`Costfloat32Taxfloat32Totalfloat32
}Parses each line into a item of given slice
funcmain() {
response, _:=http.Get("https://people.sc.fsu.edu/~jburkardt/data/csv/taxables.csv")
// define a slice with a typevartaxables []Taxable// initiate the readerr:=csv.NewReader(response.Body)
// read all lines into the referenced slice err:=r.ReadAll(&taxables)
iferr!=nil {
fmt.Println(err)
}
fmt.Println(taxables)
}TimeLayout - layout for parsing a time.Time, see format (default time.RFC3339)
Delimiter - change delimiter (default comma ',')
Int, Int8, Int16, Int32, Int64, Float32, Float64, time.Time, String