Skip to content

Commit

Permalink
Interface checks all over.
Browse files Browse the repository at this point in the history
Also some pedantry.
  • Loading branch information
rcrowley committed Mar 29, 2013
1 parent f1df2bb commit 07ad690
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions ewma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}))

Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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{})) {
Expand All @@ -112,7 +114,3 @@ func RunHealthchecks() {
func Unregister(name string) {
DefaultRegistry.Unregister(name)
}

func init() {
DefaultRegistry = NewRegistry()
}
3 changes: 3 additions & 0 deletions sample.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 07ad690

Please sign in to comment.