carlos / platform Public

analytics: snake_case JSON tags on DaySummary

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev d44e58a1b718d8cea08fc2b13f640b964d397284 parent a5d2985
2 files changed, +17 −7
  • internal/analytics/read.go +7 −7
  • internal/console/apianalytics_test.go +10 −0
diff --git a/internal/analytics/read.go b/internal/analytics/read.go
index f614637e8..bf80bcb68 100644
--- a/internal/analytics/read.go
+++ b/internal/analytics/read.go
@@ -17,13 +17,13 @@ import (
// DaySummary is one UTC day across every box.
type DaySummary struct {
- Date string
- PV int64
- Bots int64
- Bytes int64
- Visitors int64 // HLL estimate, rounded
- Hours [24]int64
- Restarted bool
+ Date string `json:"date"`
+ PV int64 `json:"pv"`
+ Bots int64 `json:"bots"`
+ Bytes int64 `json:"bytes"`
+ Visitors int64 `json:"visitors"`
+ Hours [24]int64 `json:"hours"`
+ Restarted bool `json:"restarted"`
}
// Summary is what the tab and the API render: per-day rows plus totals.
diff --git a/internal/console/apianalytics_test.go b/internal/console/apianalytics_test.go
index a47199f9a..af33e1ecd 100644
--- a/internal/console/apianalytics_test.go
+++ b/internal/console/apianalytics_test.go
@@ -127,6 +127,16 @@ func TestAPIAnalyticsSummary(t *testing.T) {
if st, _, b := rawReq(t, http.MethodGet, fx.ts.URL+"/api/cli/apps/"+fx.sqid+"/titogo/analytics?range=7d", token, ""); st != 200 {
t.Fatalf("7d: %d %s", st, b)
}
+ // Verify snake_case JSON tags
+ if !strings.Contains(body, "\"days\":[{\"date\":") {
+ t.Fatal("missing snake_case days array with date field")
+ }
+ if !strings.Contains(body, "\"pv\":") {
+ t.Fatal("missing snake_case pv field")
+ }
+ if strings.Contains(body, "\"PV\":") {
+ t.Fatal("found PascalCase PV field (should be pv)")
+ }
}
func TestAppAnalyticsPage(t *testing.T) {