mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans, usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0. Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
47 lines
641 B
Go
47 lines
641 B
Go
package csv
|
|
|
|
import (
|
|
"encoding/csv"
|
|
"os"
|
|
|
|
"github.com/hanzoai/commerce/log"
|
|
)
|
|
|
|
type Record struct {
|
|
Index int
|
|
Row []string
|
|
}
|
|
|
|
func Iterator(filename string) <-chan Record {
|
|
ch := make(chan Record)
|
|
|
|
go func() {
|
|
file, err := os.Open(filename)
|
|
defer file.Close()
|
|
if err != nil {
|
|
log.Fatal("Failed to open CSV File: %v", err)
|
|
}
|
|
|
|
reader := csv.NewReader(file)
|
|
reader.FieldsPerRecord = -1
|
|
|
|
// Skip header
|
|
reader.Read()
|
|
|
|
for i := 0; true; i++ {
|
|
// Loop until exhausted
|
|
row, err := reader.Read()
|
|
|
|
// Break on error
|
|
if err != nil {
|
|
break
|
|
}
|
|
|
|
ch <- Record{i, row}
|
|
}
|
|
close(ch)
|
|
}()
|
|
|
|
return ch
|
|
}
|