Skip to content

ghosind/go-csv

Repository files navigation

csv

test Go Report Card codecov Version Badge License Badge Go Reference

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:

  1. Define a struct with csv tags:
type Person struct {
  Name string `csv:"name"`
  Age  int    `csv:"age"`
}
  1. Prepare CSV data:
name,age
Alice,30
Bob,25
  1. Unmarshal CSV into a slice:
var people []Person
err := csv.Unmarshal([]byte(data), &people)
log.Print(people)
// Output:
// [{Alice 30} {Bob 25}]
  1. 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.

About

The Go library for serializing/deserializing CSV to/from Go structs.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages