Skip to content

Commit cfaee7b

Browse files
committed
Omit lastLogForTick from Kafka JSON when false
Add omitempty tag to LastLogForTick so the field is excluded from serialized messages when its value is false, keeping payloads lean. Add tests verifying the marshaling behavior.
1 parent f55ea2a commit cfaee7b

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

bob-events-bridge/internal/kafka/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type EventMessage struct {
1818
Timestamp uint64 `json:"timestamp"`
1919
TransactionHash string `json:"transactionHash"`
2020
Body map[string]any `json:"body"`
21-
LastLogForTick bool `json:"lastLogForTick"`
21+
LastLogForTick bool `json:"lastLogForTick,omitempty"`
2222
}
2323

2424
// TransformEventBody converts a typed bob event body into the Kafka body format

bob-events-bridge/internal/kafka/message_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package kafka
22

33
import (
4+
"encoding/json"
45
"testing"
56

67
"github.com/google/go-cmp/cmp"
@@ -303,3 +304,28 @@ func TestBuildEventMessage_LastLogForTick(t *testing.T) {
303304
assert.True(t, msg.LastLogForTick)
304305
}
305306

307+
func TestEventMessage_JSON_OmitsLastLogForTickWhenFalse(t *testing.T) {
308+
msg := EventMessage{
309+
Index: 1,
310+
Type: 0,
311+
TickNumber: 100,
312+
}
313+
314+
data, err := json.Marshal(msg)
315+
require.NoError(t, err)
316+
assert.NotContains(t, string(data), "lastLogForTick")
317+
}
318+
319+
func TestEventMessage_JSON_IncludesLastLogForTickWhenTrue(t *testing.T) {
320+
msg := EventMessage{
321+
Index: 1,
322+
Type: 0,
323+
TickNumber: 100,
324+
LastLogForTick: true,
325+
}
326+
327+
data, err := json.Marshal(msg)
328+
require.NoError(t, err)
329+
assert.Contains(t, string(data), `"lastLogForTick":true`)
330+
}
331+

0 commit comments

Comments
 (0)