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
46 lines
710 B
Go
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
|
|
}
|