ソースを参照

As Roger Peppe suggested, return concrete types.

Richard Crowley 14 年 前
コミット
87f4f4a3a2
9 ファイル変更14 行追加14 行削除
  1. 1 1
      counter.go
  2. 4 4
      ewma.go
  3. 1 1
      gauge.go
  4. 1 1
      healthcheck.go
  5. 1 1
      histogram.go
  6. 1 1
      meter.go
  7. 1 1
      registry.go
  8. 2 2
      sample.go
  9. 2 2
      timer.go

+ 1 - 1
counter.go

@@ -22,7 +22,7 @@ type StandardCounter struct {
 }
 
 // Create a new counter.
-func NewCounter() Counter {
+func NewCounter() *StandardCounter {
 	return &StandardCounter{0}
 }
 

+ 4 - 4
ewma.go

@@ -31,24 +31,24 @@ type StandardEWMA struct {
 
 // Create a new EWMA with the given alpha.  Create the clock channel and
 // start the ticker goroutine.
-func NewEWMA(alpha float64) EWMA {
+func NewEWMA(alpha float64) *StandardEWMA {
 	a := &StandardEWMA{alpha, 0, 0.0, false, make(chan bool)}
 	go a.ticker()
 	return a
 }
 
 // Create a new EWMA with alpha set for a one-minute moving average.
-func NewEWMA1() EWMA {
+func NewEWMA1() *StandardEWMA {
 	return NewEWMA(1 - math.Exp(-5.0 / 60.0 / 1))
 }
 
 // Create a new EWMA with alpha set for a five-minute moving average.
-func NewEWMA5() EWMA {
+func NewEWMA5() *StandardEWMA {
 	return NewEWMA(1 - math.Exp(-5.0 / 60.0 / 5))
 }
 
 // Create a new EWMA with alpha set for a fifteen-minute moving average.
-func NewEWMA15() EWMA {
+func NewEWMA15() *StandardEWMA {
 	return NewEWMA(1 - math.Exp(-5.0 / 60.0 / 15))
 }
 

+ 1 - 1
gauge.go

@@ -20,7 +20,7 @@ type StandardGauge struct {
 }
 
 // Create a new gauge.
-func NewGauge() Gauge {
+func NewGauge() *StandardGauge {
 	return &StandardGauge{0}
 }
 

+ 1 - 1
healthcheck.go

@@ -22,7 +22,7 @@ type StandardHealthcheck struct {
 
 // Create a new healthcheck, which will use the given function to update
 // its status.
-func NewHealthcheck(f func(Healthcheck)) Healthcheck {
+func NewHealthcheck(f func(Healthcheck)) *StandardHealthcheck {
 	return &StandardHealthcheck{nil, f}
 }
 

+ 1 - 1
histogram.go

@@ -40,7 +40,7 @@ type histogramV struct {
 
 // Create a new histogram with the given Sample.  Create the communication
 // channels and start the synchronizing goroutine.
-func NewHistogram(s Sample) Histogram {
+func NewHistogram(s Sample) *StandardHistogram {
 	h := &StandardHistogram{
 		s,
 		make(chan int64),

+ 1 - 1
meter.go

@@ -34,7 +34,7 @@ type meterV struct {
 
 // Create a new meter.  Create the communication channels and start the
 // synchronizing goroutine.
-func NewMeter() Meter {
+func NewMeter() *StandardMeter {
 	m := &StandardMeter{
 		make(chan int64),
 		make(chan meterV),

+ 1 - 1
registry.go

@@ -54,7 +54,7 @@ type StandardRegistry struct {
 }
 
 // Create a new registry.
-func NewRegistry() Registry {
+func NewRegistry() *StandardRegistry {
 	return &StandardRegistry {
 		&sync.Mutex{},
 		make(map[string]Counter),

+ 2 - 2
sample.go

@@ -35,7 +35,7 @@ type ExpDecaySample struct {
 
 // Create a new exponentially-decaying sample with the given reservoir size
 // and alpha.
-func NewExpDecaySample(reservoirSize int, alpha float64) Sample {
+func NewExpDecaySample(reservoirSize int, alpha float64) *ExpDecaySample {
 	s := &ExpDecaySample{
 		reservoirSize,
 		alpha,
@@ -132,7 +132,7 @@ type UniformSample struct {
 }
 
 // Create a new uniform sample with the given reservoir size.
-func NewUniformSample(reservoirSize int) Sample {
+func NewUniformSample(reservoirSize int) *UniformSample {
 	s := &UniformSample{
 		reservoirSize,
 		make(chan int64),

+ 2 - 2
timer.go

@@ -29,14 +29,14 @@ type StandardTimer struct {
 }
 
 // Create a new timer with the given Histogram and Meter.
-func NewCustomTimer(h Histogram, m Meter) Timer {
+func NewCustomTimer(h Histogram, m Meter) *StandardTimer {
 	return &StandardTimer{h, m}
 }
 
 // Create a new timer with a standard histogram and meter.  The histogram
 // will use an exponentially-decaying sample with the same reservoir size
 // and alpha as UNIX load averages.
-func NewTimer() Timer {
+func NewTimer() *StandardTimer {
 	return &StandardTimer{
 		NewHistogram(NewExpDecaySample(1028, 0.015)),
 		NewMeter(),