Files
commerce/util/json/iterator.go
zeekay 1943f1c093 Hanzo Commerce
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
2026-09-23 21:52:16 -07:00

46 lines
710 B
Go

package json
import (
"bufio"
"fmt"
"io"
"log"
"os"
)
type Record struct {
Data string
Index int
}
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(fmt.Sprintf("Failed to open JSON File: %v", err))
}
r := bufio.NewReader(file)
line := 1
for {
data, err := r.ReadString(10) // 0x0A separator = newline
ch <- Record{data, line}
if err == io.EOF {
// do something here
ch <- Record{data, line}
break
} else if err != nil {
log.Fatal(fmt.Sprintf("Failed to open JSON File: %v", err))
}
line = line + 1
}
close(ch)
}()
return ch
}