MCPcopy
hub / github.com/prometheus/client_golang / toNormalizedJSON

Function toNormalizedJSON

prometheus/utils_test.go:53–64  ·  prometheus/utils_test.go::toNormalizedJSON

toNormalizedJSON removes fake random space from proto JSON original marshaller. It is required, so we can compare proto messages in json format. Read more in https://github.com/golang/protobuf/issues/1121

(m proto.Message)

Source from the content-addressed store, hash-verified

51// It is required, so we can compare proto messages in json format.
52// Read more in https://github.com/golang/protobuf/issues/1121
53func toNormalizedJSON(m proto.Message) string {
54 mAsJSON, err := protojson.Marshal(m)
55 if err != nil {
56 panic(err)
57 }
58
59 buffer := new(bytes.Buffer)
60 if err := json.Compact(buffer, mAsJSON); err != nil {
61 panic(err)
62 }
63 return buffer.String()
64}

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected