github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/countlog/stats/counter.go (about)

     1  package stats
     2  
     3  import "github.com/v2pro/plz/countlog/spi"
     4  
     5  type countEvent struct {
     6  	*Window
     7  	site *spi.LogSite
     8  	extractor dimensionExtractor
     9  }
    10  
    11  func (state *countEvent) Handle(event *spi.Event) {
    12  	lock, dimensions := state.Window.Mutate()
    13  	lock.Lock()
    14  	counter := state.extractor.Extract(event, dimensions, NewCounterMonoid)
    15  	*(counter.(*CounterMonoid)) += CounterMonoid(1)
    16  	lock.Unlock()
    17  }
    18  
    19  func (state *countEvent) GetWindow() *Window {
    20  	return state.Window
    21  }
    22  
    23  func (state *countEvent) LogSite() *spi.LogSite {
    24  	return state.site
    25  }