csv

The Go library for serializing/deserializing CSV to/from Go structs.
Features
- Map CSV headers to struct fields using
csv tags (or field name when tag omitted).
- Support basic types: string, ints, uints, floats, bool.
- Easy to use API for marshaling and unmarshaling.
Installation
Run the following command to install the package:
go get github.com/ghosind/go-csv
Getting Started
Here's a quick example to get you started:
- Define a struct with
csv tags:
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,25
Tests
Run tests using the following command:
go test ./...
License
This project is licensed under the MIT License, see the LICENSE file for details.