Fix [Client] [Exporting Messages] JSON Format

- [+] fix(json_exporter.go): update Export method to encode messages as a JSON array instead of individually
This commit is contained in:
H0llyW00dzZ 2025-01-24 15:01:18 +07:00
parent 3d17ce82ff
commit ac6703339b
Signed by: H0llyW00dzZ
GPG Key ID: A0F9424A7002343A

View File

@ -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
}