Bladeren bron

Interface checks all over.

Also some pedantry.
Richard Crowley 12 jaren geleden
bovenliggende
commit
07ad690f21
9 gewijzigde bestanden met toevoegingen van 28 en 6 verwijderingen
  1. 3 0
      counter.go
  2. 3 0
      ewma.go
  3. 3 0
      gauge.go
  4. 3 0
      healthcheck.go
  5. 3 0
      histogram.go
  6. 3 0
      meter.go
  7. 4 6
      registry.go
  8. 3 0
      sample.go
  9. 3 0
      timer.go

+ 3 - 0
counter.go

@@ -19,6 +19,9 @@ type StandardCounter struct {
 	count int64
 }
 
+// Force the compiler to check that StandardCounter implements Counter.
+var _ Counter = &StandardCounter{}
+
 // Create a new counter.
 func NewCounter() *StandardCounter {
 	return &StandardCounter{0}

+ 3 - 0
ewma.go

@@ -26,6 +26,9 @@ type StandardEWMA struct {
 	out       chan float64
 }
 
+// Force the compiler to check that StandardEWMA implements EWMA.
+var _ EWMA = &StandardEWMA{}
+
 // Create a new EWMA with the given alpha.  Create the clock channel and
 // start the ticker goroutine.
 func NewEWMA(alpha float64) *StandardEWMA {

+ 3 - 0
gauge.go

@@ -17,6 +17,9 @@ type StandardGauge struct {
 	value int64
 }
 
+// Force the compiler to check that StandardGauge implements Gauge.
+var _ Gauge = &StandardGauge{}
+
 // Create a new gauge.
 func NewGauge() *StandardGauge {
 	return &StandardGauge{0}

+ 3 - 0
healthcheck.go

@@ -18,6 +18,9 @@ type StandardHealthcheck struct {
 	f   func(Healthcheck)
 }
 
+// Force the compiler to check that StandardHealthcheck implements Healthcheck.
+var _ Healthcheck = &StandardHealthcheck{}
+
 // Create a new healthcheck, which will use the given function to update
 // its status.
 func NewHealthcheck(f func(Healthcheck)) *StandardHealthcheck {

+ 3 - 0
histogram.go

@@ -31,6 +31,9 @@ type StandardHistogram struct {
 	reset chan bool
 }
 
+// Force the compiler to check that StandardHistogram implements Histogram.
+var _ Histogram = &StandardHistogram{}
+
 // A histogramV contains all the values that would need to be passed back
 // from the synchronizing goroutine.
 type histogramV struct {

+ 3 - 0
meter.go

@@ -25,6 +25,9 @@ type StandardMeter struct {
 	ticker *time.Ticker
 }
 
+// Force the compiler to check that StandardMeter implements Meter.
+var _ Meter = &StandardMeter{}
+
 // A meterV contains all the values that would need to be passed back
 // from the synchronizing goroutine.
 type meterV struct {

+ 4 - 6
registry.go

@@ -8,6 +8,7 @@ import "sync"
 // This is an interface so as to encourage other structs to implement
 // the Registry API as appropriate.
 type Registry interface {
+
 	// Call the given function for each registered metric.
 	Each(func(string, interface{}))
 
@@ -22,6 +23,7 @@ type Registry interface {
 
 	// Unregister the metric with the given name.
 	Unregister(string)
+
 }
 
 // The standard implementation of a Registry is a mutex-protected map
@@ -31,7 +33,7 @@ type StandardRegistry struct {
 	metrics map[string]interface{}
 }
 
-// Check interface.
+// Force the compiler to check that StandardRegistry implements Registry.
 var _ Registry = &StandardRegistry{}
 
 // Create a new registry.
@@ -86,7 +88,7 @@ func (r *StandardRegistry) Unregister(name string) {
 	delete(r.metrics, name)
 }
 
-var DefaultRegistry *StandardRegistry
+var DefaultRegistry *StandardRegistry = NewRegistry()
 
 // Call the given function for each registered metric.
 func Each(f func(string, interface{})) {
@@ -112,7 +114,3 @@ func RunHealthchecks() {
 func Unregister(name string) {
 	DefaultRegistry.Unregister(name)
 }
-
-func init() {
-	DefaultRegistry = NewRegistry()
-}

+ 3 - 0
sample.go

@@ -34,6 +34,9 @@ type ExpDecaySample struct {
 	reset         chan bool
 }
 
+// Force the compiler to check that ExpDecaySample implements Sample.
+var _ Sample = &ExpDecaySample{}
+
 // Create a new exponentially-decaying sample with the given reservoir size
 // and alpha.
 func NewExpDecaySample(reservoirSize int, alpha float64) *ExpDecaySample {

+ 3 - 0
timer.go

@@ -29,6 +29,9 @@ type StandardTimer struct {
 	m Meter
 }
 
+// Force the compiler to check that StandardTimer implements Timer.
+var _ Timer = &StandardTimer{}
+
 // Create a new timer with the given Histogram and Meter.
 func NewCustomTimer(h Histogram, m Meter) *StandardTimer {
 	return &StandardTimer{h, m}