https://github.com/cego/go-csv
Golang package for parsing CSV
https://github.com/cego/go-csv
Last synced: 2 months ago
JSON representation
Golang package for parsing CSV
- Host: GitHub
- URL: https://github.com/cego/go-csv
- Owner: cego
- License: mit
- Created: 2018-08-21T11:37:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-08-23T12:04:21.000Z (almost 8 years ago)
- Last Synced: 2025-08-15T04:55:57.310Z (10 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
Golang package for reading and writing CSV data
===============================================
Golang package for reading and writing CSV data as described in [RFC 4180](https://tools.ietf.org/html/rfc4180).
Is was written as a replacement of the stdlib package encoding/csv in cases where that interpretation of the RFC is
lacking. Specifically, we want to preserve carriage returns inside fields.
To keep this package simple, it does not attempt to implement all features of encoding/csv and be a complete drop-in
replacement. You will likely need to adjust your code slightly to use this package instead of encoding/csv.
Examples
--------
Reading CSV formatted data.
import (
"strings"
"github.com/cego/go-csv"
)
reader := csv.NewReader(strings.NewReader("fi,fy\nfo,fum"))
records, err := reader.ReadAll()
if err != nil && err != io.EOF {
panic(err)
}
// records is now [ ["fi","fy"], ["fo","fum"] ]
Writing CSV formatted data.
import (
"strings"
"github.com/cego/go-csv"
)
builder := strings.Builder{}
writer := csv.NewWriter(&builder)
err := writer.WriteAll([][]string{ {"fi", "fy"}, {"fo", "fum"} })
if err != nil {
panic(err)
}
// builder.String() is now "fi","fy"\r\n"fo","fum"