From d0ff7b58c58a8ba964cba87f8175476b28841355 Mon Sep 17 00:00:00 2001 From: Alvarez <140459501+prestoalvarez@users.noreply.github.com> Date: Tue, 21 Oct 2025 15:34:34 +0200 Subject: [PATCH] Update json.go --- metrics/json.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/metrics/json.go b/metrics/json.go index 6b134d477b..b6bd20c017 100644 --- a/metrics/json.go +++ b/metrics/json.go @@ -6,10 +6,15 @@ import ( "time" ) +// Shared JSON serialization for registry types to avoid duplication. +func marshalRegistryJSON(r Registry) ([]byte, error) { + return json.Marshal(r.GetAll()) +} + // MarshalJSON returns a byte slice containing a JSON representation of all // the metrics in the Registry. func (r *StandardRegistry) MarshalJSON() ([]byte, error) { - return json.Marshal(r.GetAll()) + return marshalRegistryJSON(r) } // WriteJSON writes metrics from the given registry periodically to the @@ -27,5 +32,5 @@ func WriteJSONOnce(r Registry, w io.Writer) { } func (r *PrefixedRegistry) MarshalJSON() ([]byte, error) { - return json.Marshal(r.GetAll()) + return marshalRegistryJSON(r) }