Give every API value with a unit as a number (closes #199)
check / check (push) Waiting to run

A value with a unit is now a number, and its field name ends in the
unit, as the vendored API_POLICIES.md requires. @meta.execution_time
becomes execution_time_ms. In the stats answers, uptime,
connection_duration, memory_usage and whois_stats.current_interval
become uptime_seconds, connection_duration_seconds, memory_usage_bytes
and whois_stats.current_interval_seconds. connection_duration_seconds
is null while the feed is not connected. The status page formats the
numbers itself. REPO_POLICIES.md is re-vendored from the same
sneak/prompts commit.

Model: opus-5-5
This commit is contained in:
2026-10-27 19:06:07 +00:00
parent a671b8a0b0
commit 7752950c84
9 changed files with 456 additions and 74 deletions
+13 -4
View File
@@ -53,6 +53,15 @@ func (rw *responseWriter) Header() http.Header {
return rw.ResponseWriter.Header()
}
// The @meta object JSONResponseMiddleware adds to a JSON answer: its key, and
// the keys of its fields.
const (
jsonKeyMeta = "@meta"
metaKeyTimeZone = "time_zone"
metaKeyAPIVersion = "api_version"
metaKeyExecutionTimeMs = "execution_time_ms"
)
// JSONResponseMiddleware is an HTTP middleware that wraps all JSON responses
// with a @meta field containing execution metadata. The metadata includes the
// time zone (always UTC), API version, and request execution time in milliseconds.
@@ -106,10 +115,10 @@ func JSONResponseMiddleware(next http.Handler) http.Handler {
}
// Add @meta field
originalResponse["@meta"] = map[string]any{
"time_zone": "UTC",
"api_version": 1,
"execution_time": fmt.Sprintf("%d ms", execTime.Milliseconds()),
originalResponse[jsonKeyMeta] = map[string]any{
metaKeyTimeZone: "UTC",
metaKeyAPIVersion: 1,
metaKeyExecutionTimeMs: execTime.Milliseconds(),
}
// Write the enhanced response