The Go library for serializing/deserializing CSV to/from Go structs.
- Map CSV headers to struct fields using
csvtags (or field name when tag omitted). - Support basic types: string, ints, uints, floats, bool.
- Easy to use API for marshaling and unmarshaling.
Run the following command to install the package:
go get github.com/ghosind/go-csvHere's a quick example to get you started:
- Define a struct with
csvtags:
type Person struct {
Name string `csv:"name"`
Age int `csv:"age"`
}- Prepare CSV data:
name,age
Alice,30
Bob,25- Unmarshal CSV into a slice:
var people []Person
err := csv.Unmarshal([]byte(data), &people)
log.Print(people)
// Output:
// [{Alice 30} {Bob 25}]- Marshal a slice back to CSV:
data, err := csv.Marshal(people)
log.Print(string(data))
// Output:
// name,age
// Alice,30
// Bob,25Run tests using the following command:
go test ./...This project is licensed under the MIT License, see the LICENSE file for details.