Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

csv

The package provides a simple typed parser for csv/dsv files.

Installation

go get github.com/tomaspavlic/csv

Usage

Import

import (
// import the package"github.com/tomaspavlic/csv"
)

Define type

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
}

Read

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)
}

Reader settings

TimeLayout - layout for parsing a time.Time, see format (default time.RFC3339)

Delimiter - change delimiter (default comma ',')

Supported types

Int, Int8, Int16, Int32, Int64, Float32, Float64, time.Time, String

About

The package provides a simple typed parser for csv/dsv files.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages