From 4de658fca2dc28576a5771bfc103bf5bf92c25e1 Mon Sep 17 00:00:00 2001 From: H0llyW00dzZ Date: Fri, 24 Jan 2025 08:01:49 +0000 Subject: [PATCH] Fix [Client] [Exporting Messages] JSON Format (#6) - [+] fix(json_exporter.go): update Export method to encode messages as a JSON array instead of individually Reviewed-on: https://git.b0zal.io/H0llyW00dzZ/imap/pulls/6 Co-authored-by: H0llyW00dzZ Co-committed-by: H0llyW00dzZ --- export/json_exporter.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/export/json_exporter.go b/export/json_exporter.go index 73cb0e3..d124040 100644 --- a/export/json_exporter.go +++ b/export/json_exporter.go @@ -19,12 +19,11 @@ type JSONExporter struct { Encoder JSONEncoderFunc } -// Export writes messages to the writer using the custom JSON encoder +// Export writes messages to the writer as a JSON array using the custom JSON encoder func (e *JSONExporter) Export(messages []map[string]any, writer io.Writer) error { - for _, msg := range messages { - if err := e.Encoder(msg, writer); err != nil { - return fmt.Errorf("failed to encode message to JSON: %v", err) - } + // Use the encoder to write the entire slice as a JSON array + if err := e.Encoder(messages, writer); err != nil { + return fmt.Errorf("failed to encode messages to JSON: %v", err) } return nil }