Skip to content

Go CSV reader like Python's DictReader

License

Notifications You must be signed in to change notification settings

earthboundkid/csv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

csv GoDoc Go Report Card Coverage Status

Go CSV reader like Python's DictReader.

go get github.com/earthboundkid/csv/v2

For performance comparison to other libraries, see this benchmark gist. As of this writing, this library is 40% faster and uses 70% less memory than its closest competitor.

Example

Source CSV

first_name,last_name,username
"Rob","Pike",rob
Ken,Thompson,ken
"Robert","Griesemer","gri"

User type

type User struct {
    Username string `csv:"username"`
    First    string `csv:"first_name"`
    Last     string `csv:"last_name"`
}

Scanning file

var user User
for err := range csv.Scan(csv.Options{Reader: src}, &user) {
    if err != nil {
        // Do something
    }
    fmt.Println(user.Username)
}
// Output:
// rob
// ken
// gri