88 "sync"
99)
1010
11- // DuplicateMetric is the error returned by Registry.Register when a metric
12- // already exists. If you mean to Register that metric you must first
11+ // DuplicateMetric is the error returned by Registry. Register when a metric
12+ // already exists. If you mean to Register that metric you must first
1313// Unregister the existing metric.
1414type DuplicateMetric string
1515
@@ -20,11 +20,11 @@ func (err DuplicateMetric) Error() string {
2020// A Registry holds references to a set of metrics by name and can iterate
2121// over them, calling callback functions provided by the user.
2222//
23- // This is an interface so as to encourage other structs to implement
23+ // This is an interface to encourage other structs to implement
2424// the Registry API as appropriate.
2525type Registry interface {
2626
27- // Call the given function for each registered metric.
27+ // Each call the given function for each registered metric.
2828 Each (func (string , interface {}))
2929
3030 // Get the metric by the given name or nil if none is registered.
@@ -33,15 +33,15 @@ type Registry interface {
3333 // GetAll metrics in the Registry.
3434 GetAll () map [string ]map [string ]interface {}
3535
36- // Gets an existing metric or registers the given one.
36+ // GetOrRegister gets an existing metric or registers the given one.
3737 // The interface can be the metric to register if not found in registry,
3838 // or a function returning the metric for lazy instantiation.
3939 GetOrRegister (string , interface {}) interface {}
4040
4141 // Register the given metric under the given name.
4242 Register (string , interface {}) error
4343
44- // Run all registered healthchecks.
44+ // RunHealthchecks run all registered healthchecks.
4545 RunHealthchecks ()
4646
4747 // Unregister the metric with the given name.
@@ -52,7 +52,7 @@ type orderedRegistry struct {
5252 StandardRegistry
5353}
5454
55- // Call the given function for each registered metric.
55+ // Each call the given function for each registered metric.
5656func (r * orderedRegistry ) Each (f func (string , interface {})) {
5757 var names []string
5858 reg := r .registered ()
@@ -75,13 +75,13 @@ func NewOrderedRegistry() Registry {
7575 return new (orderedRegistry )
7676}
7777
78- // The standard implementation of a Registry uses sync.map
78+ // StandardRegistry the standard implementation of a Registry uses sync.map
7979// of names to metrics.
8080type StandardRegistry struct {
8181 metrics sync.Map
8282}
8383
84- // Call the given function for each registered metric.
84+ // Each call the given function for each registered metric.
8585func (r * StandardRegistry ) Each (f func (string , interface {})) {
8686 for name , i := range r .registered () {
8787 f (name , i )
@@ -94,7 +94,7 @@ func (r *StandardRegistry) Get(name string) interface{} {
9494 return item
9595}
9696
97- // Gets an existing metric or creates and registers a new one. Threadsafe
97+ // GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
9898// alternative to calling Get and Register on failure.
9999// The interface can be the metric to register if not found in registry,
100100// or a function returning the metric for lazy instantiation.
@@ -114,7 +114,7 @@ func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{}
114114 return item
115115}
116116
117- // Register the given metric under the given name. Returns a DuplicateMetric
117+ // Register the given metric under the given name. Returns a DuplicateMetric
118118// if a metric by the given name is already registered.
119119func (r * StandardRegistry ) Register (name string , i interface {}) error {
120120 // fast path
@@ -133,7 +133,7 @@ func (r *StandardRegistry) Register(name string, i interface{}) error {
133133 return nil
134134}
135135
136- // Run all registered healthchecks.
136+ // RunHealthchecks run all registered healthchecks.
137137func (r * StandardRegistry ) RunHealthchecks () {
138138 r .metrics .Range (func (key , value any ) bool {
139139 if h , ok := value .(Healthcheck ); ok {
@@ -263,7 +263,7 @@ func NewPrefixedChildRegistry(parent Registry, prefix string) Registry {
263263 }
264264}
265265
266- // Call the given function for each registered metric.
266+ // Each call the given function for each registered metric.
267267func (r * PrefixedRegistry ) Each (fn func (string , interface {})) {
268268 wrappedFn := func (prefix string ) func (string , interface {}) {
269269 return func (name string , iface interface {}) {
@@ -295,7 +295,7 @@ func (r *PrefixedRegistry) Get(name string) interface{} {
295295 return r .underlying .Get (realName )
296296}
297297
298- // Gets an existing metric or registers the given one.
298+ // GetOrRegister gets an existing metric or registers the given one.
299299// The interface can be the metric to register if not found in registry,
300300// or a function returning the metric for lazy instantiation.
301301func (r * PrefixedRegistry ) GetOrRegister (name string , metric interface {}) interface {} {
@@ -309,7 +309,7 @@ func (r *PrefixedRegistry) Register(name string, metric interface{}) error {
309309 return r .underlying .Register (realName , metric )
310310}
311311
312- // Run all registered healthchecks.
312+ // RunHealthchecks run all registered healthchecks.
313313func (r * PrefixedRegistry ) RunHealthchecks () {
314314 r .underlying .RunHealthchecks ()
315315}
@@ -331,7 +331,7 @@ var (
331331 AccountingRegistry = NewRegistry () // registry used in swarm
332332)
333333
334- // Call the given function for each registered metric.
334+ // Each call the given function for each registered metric.
335335func Each (f func (string , interface {})) {
336336 DefaultRegistry .Each (f )
337337}
@@ -341,7 +341,7 @@ func Get(name string) interface{} {
341341 return DefaultRegistry .Get (name )
342342}
343343
344- // Gets an existing metric or creates and registers a new one. Threadsafe
344+ // GetOrRegister gets an existing metric or creates and registers a new one. Threadsafe
345345// alternative to calling Get and Register on failure.
346346func GetOrRegister (name string , i interface {}) interface {} {
347347 return DefaultRegistry .GetOrRegister (name , i )
@@ -353,15 +353,15 @@ func Register(name string, i interface{}) error {
353353 return DefaultRegistry .Register (name , i )
354354}
355355
356- // Register the given metric under the given name. Panics if a metric by the
356+ // MustRegister register the given metric under the given name. Panics if a metric by the
357357// given name is already registered.
358358func MustRegister (name string , i interface {}) {
359359 if err := Register (name , i ); err != nil {
360360 panic (err )
361361 }
362362}
363363
364- // Run all registered healthchecks.
364+ // RunHealthchecks run all registered healthchecks.
365365func RunHealthchecks () {
366366 DefaultRegistry .RunHealthchecks ()
367367}
0 commit comments