Update json.go

This commit is contained in:
Alvarez 2025-10-21 15:34:34 +02:00 committed by GitHub
parent 0a8b820725
commit d0ff7b58c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,10 +6,15 @@ import (
"time" "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 // MarshalJSON returns a byte slice containing a JSON representation of all
// the metrics in the Registry. // the metrics in the Registry.
func (r *StandardRegistry) MarshalJSON() ([]byte, error) { func (r *StandardRegistry) MarshalJSON() ([]byte, error) {
return json.Marshal(r.GetAll()) return marshalRegistryJSON(r)
} }
// WriteJSON writes metrics from the given registry periodically to the // 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) { func (r *PrefixedRegistry) MarshalJSON() ([]byte, error) {
return json.Marshal(r.GetAll()) return marshalRegistryJSON(r)
} }