Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelwp/go-csv
The go-csv package provides an easy-to-use interface for generating CSV files with concurrent processing
https://github.com/michaelwp/go-csv
concurrency csv go golang stream
Last synced: 6 days ago
JSON representation
The go-csv package provides an easy-to-use interface for generating CSV files with concurrent processing
- Host: GitHub
- URL: https://github.com/michaelwp/go-csv
- Owner: michaelwp
- License: mit
- Created: 2024-07-14T16:08:50.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-07-15T03:36:32.000Z (7 months ago)
- Last Synced: 2024-09-18T10:10:47.759Z (5 months ago)
- Topics: concurrency, csv, go, golang, stream
- Language: Go
- Homepage: https://goblog.dev/articles/39
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-csv
The `go-csv` package provides an easy-to-use interface for generating CSV files with concurrent processing. This package is particularly useful for handling large datasets and performing stream processing.
For detail explanation about concurrent & streaming processing please visit [Stream and Concurrent Processing in Programming](https://goblog.dev/articles/39)## Installation
To install the package, use `go get`:
```bash
go get github.com/michaelwp/go-csv
```## Usage
### Generate Function
The `Generate` function creates a CSV file with the given headers and data.
#### Example:
```go
package mainimport (
"context"
"fmt"
"log"
"strconv"
"time"gocsv "github.com/michaelwp/go-csv"
)func main() {
filePath := "output"
headers := []string{"No", "Name", "Age", "Occupation"}
data := GenerateSampleData(1000000)ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()err := gocsv.Generate(ctx, filePath, headers, data)
if err != nil {
log.Println("failed to create csv", err)
return
}fmt.Println("csv generated successfully")
}func GenerateSampleData(rowNumber int) [][]string {
var data = make([][]string, rowNumber)for i := 0; i < rowNumber; i++ {
noStr := strconv.Itoa(i + 1)
data[i] = []string{noStr, "John Doe", "30", "Engineer"}
}return data
}