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.
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