refactor(go): remove source endpoint from realtime snapshots

This commit is contained in:
lingniu
2026-07-02 21:16:39 +08:00
parent 04ca0d15d8
commit ef2be36fce
3 changed files with 30 additions and 30 deletions

View File

@@ -14,7 +14,6 @@ type Snapshot struct {
EventID string `json:"event_id,omitempty"`
EventTimeMS int64 `json:"event_time_ms"`
ReceivedAtMS int64 `json:"received_at_ms"`
SourceEndpoint string `json:"source_endpoint,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
FieldTimesMS map[string]int64 `json:"field_times_ms,omitempty"`
Parsed map[string]any `json:"parsed,omitempty"`

View File

@@ -45,7 +45,6 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err
EventID: env.StableEventID(),
EventTimeMS: eventMS,
ReceivedAtMS: env.ReceivedAtMS,
SourceEndpoint: env.SourceEndpoint,
Fields: cloneFields(env.Fields),
FieldTimesMS: fieldTimes(env.Fields, eventMS),
Parsed: cloneMap(env.Parsed),
@@ -69,7 +68,6 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err
protocolSnapshot.EventTimeMS = eventMS
protocolSnapshot.EventID = env.StableEventID()
protocolSnapshot.ReceivedAtMS = env.ReceivedAtMS
protocolSnapshot.SourceEndpoint = env.SourceEndpoint
}
protocolSnapshot.UpdatedAtMS = nowMS
}
@@ -105,7 +103,6 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err
merged.EventTimeMS = eventMS
merged.EventID = env.StableEventID()
merged.ReceivedAtMS = env.ReceivedAtMS
merged.SourceEndpoint = env.SourceEndpoint
}
merged.Protocols = protocols
merged.UpdatedAtMS = nowMS

View File

@@ -382,6 +382,7 @@ func TestHandlerReturnsMergedSnapshot(t *testing.T) {
if err := repo.Update(context.Background(), envelope.FrameEnvelope{
Protocol: envelope.ProtocolJT808,
VIN: "VIN001",
SourceEndpoint: "115.231.168.135:43625",
EventTimeMS: 1000,
ReceivedAtMS: 1100,
Fields: map[string]any{envelope.FieldSpeedKMH: 12.3},
@@ -398,6 +399,9 @@ func TestHandlerReturnsMergedSnapshot(t *testing.T) {
if !stringsContains(rec.Body.String(), `"vin":"VIN001"`) {
t.Fatalf("unexpected body: %s", rec.Body.String())
}
if stringsContains(rec.Body.String(), "source_endpoint") {
t.Fatalf("realtime snapshot should not expose source_endpoint: %s", rec.Body.String())
}
}
func TestHandlerReturnsPhoneOnlyVehicleKeySnapshot(t *testing.T) {