github.com/haraldrudell/parl@v0.4.176/counter/factory.go (about)

     1  /*
     2  © 2022–present Harald Rudell <harald.rudell@gmail.com> (https://haraldrudell.github.io/haraldrudell/)
     3  ISC License
     4  */
     5  
     6  package counter
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/haraldrudell/parl"
    12  )
    13  
    14  var CountersFactory parl.CountersFactory = &countersFactory{}
    15  
    16  type countersFactory struct{}
    17  
    18  func (ff *countersFactory) NewCounters(useCounters bool, g0 parl.GoGen) (counters parl.Counters) {
    19  	if !useCounters {
    20  		return &countersNil{}
    21  	}
    22  	return newCounters(g0)
    23  }
    24  
    25  type countersNil struct{}
    26  
    27  var _ parl.Counters = &countersNil{}
    28  
    29  func (tn *countersNil) GetOrCreateCounter(name parl.CounterID, period ...time.Duration) (counter parl.Counter) {
    30  	return &counterNil{}
    31  }
    32  func (tn *countersNil) GetOrCreateDatapoint(name parl.CounterID, period time.Duration) (datapoint parl.Datapoint) {
    33  	return &datapointNil{}
    34  }
    35  
    36  type counterNil struct{}
    37  
    38  var _ parl.Counter = &counterNil{}
    39  
    40  //var _ parl.RateCounterValues = &counterNil{}
    41  
    42  func (tn *counterNil) Inc() (counters parl.Counter)            { return tn }
    43  func (tn *counterNil) Dec() (counters parl.Counter)            { return tn }
    44  func (tn *counterNil) Add(delta int64) (counters parl.Counter) { return tn }
    45  
    46  type datapointNil struct{}
    47  
    48  var _ parl.Datapoint = &datapointNil{}
    49  
    50  func (tn *datapointNil) SetValue(value uint64) (datapoint parl.Datapoint) { return }