appendJSONL adds items to a file, one JSON object per line.
(path string, items []T)
| 222 | |
| 223 | // appendJSONL adds items to a file, one JSON object per line. |
| 224 | func appendJSONL[T any](path string, items []T) error { |
| 225 | if len(items) == 0 { |
| 226 | return nil |
| 227 | } |
| 228 | f, err := os.OpenFile(path, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644) |
| 229 | if err != nil { |
| 230 | return err |
| 231 | } |
| 232 | if err := writeJSONL(f, items); err != nil { |
| 233 | f.Close() |
| 234 | return err |
| 235 | } |
| 236 | return f.Close() |
| 237 | } |
| 238 | |
| 239 | func writeJSONL[T any](w io.Writer, items []T) error { |
| 240 | enc := json.NewEncoder(w) |