feat: exporter api, json exporter

This commit is contained in:
abelith committed 2026-08-16 22:39:42 +05:00
1 parent 4de3218c40
commit 92cb9267fc
3 files changed
+83 -6

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
package json
import (
"context"
"encoding/json"
"github.com/abelith/spellbook/internal/adapters/exporter"
"github.com/abelith/spellbook/internal/models"
"io"
)
func init() {
exporter.Register("jsonl", &JsonlExporter{})
}
type JsonlExporter struct{}
func (je *JsonlExporter) Export(ctx context.Context, ch <-chan models.Spell, w io.Writer) error {
encoder := json.NewEncoder(w)
for {
select {
case <-ctx.Done():
return ctx.Err()
case spell, ok := <-ch:
if !ok {
return nil
}
if err := encoder.Encode(&spell); err != nil {
return err
}
}
}
}