1
0

Fixed var naming in ListenerCounter.

This commit is contained in:
Alexander Andreev 2025-01-05 18:34:15 +04:00
parent 00bac090bc
commit a8a9a991d4
Signed by: Arav
GPG Key ID: 25969B23DCB5CA34

View File

@ -10,8 +10,8 @@ import (
// ListenerCounter stores the current, overall and peak numbers of listeners. // ListenerCounter stores the current, overall and peak numbers of listeners.
type ListenerCounter struct { type ListenerCounter struct {
sync.RWMutex sync.RWMutex
current, peak int64 current, currentPeak int64
overall, cur_peak int64 overall, peak int64
} }
// NewListenerCounter returns a new ListenerCounter struct instance. // NewListenerCounter returns a new ListenerCounter struct instance.
@ -31,7 +31,7 @@ func (l *ListenerCounter) Peak() int64 {
// CurrentPeak returns a peak number of listeners for a currently playing song. // CurrentPeak returns a peak number of listeners for a currently playing song.
func (l *ListenerCounter) CurrentPeak() int64 { func (l *ListenerCounter) CurrentPeak() int64 {
return l.cur_peak return l.currentPeak
} }
// Overall returns an overall number of listeners for a currently playing song. // Overall returns an overall number of listeners for a currently playing song.
@ -46,12 +46,12 @@ func (l *ListenerCounter) Inc() int64 {
panic("a current number of listeners exceeded MaxInt64") panic("a current number of listeners exceeded MaxInt64")
} }
l.current++ l.current++
if l.current > l.currentPeak {
l.currentPeak = l.current
}
if l.current > l.peak { if l.current > l.peak {
l.peak = l.current l.peak = l.current
} }
if l.current > l.cur_peak {
l.cur_peak = l.current
}
if l.overall == math.MaxInt64 { if l.overall == math.MaxInt64 {
panic("an overall number of listeners exceeded MaxInt64") panic("an overall number of listeners exceeded MaxInt64")
} }
@ -72,9 +72,9 @@ func (l *ListenerCounter) Dec() (int64, error) {
// Reset current peak and overall listeners for a song that is playing. // Reset current peak and overall listeners for a song that is playing.
// And return its values. // And return its values.
func (l *ListenerCounter) Reset() (overall, peak int64) { func (l *ListenerCounter) Reset() (overall, peak int64) {
peak = l.cur_peak peak = l.peak
l.cur_peak = l.current
overall = l.overall overall = l.overall
l.peak = l.current
l.overall = l.current l.overall = l.current
return return
} }
@ -82,12 +82,12 @@ func (l *ListenerCounter) Reset() (overall, peak int64) {
func (l *ListenerCounter) MarshalJSON() ([]byte, error) { func (l *ListenerCounter) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct { return json.Marshal(&struct {
Current int64 `json:"current"` Current int64 `json:"current"`
CurPeak int64 `json:"current_peak"`
Peak int64 `json:"peak"` Peak int64 `json:"peak"`
Overall int64 `json:"overall"` Overall int64 `json:"overall"`
CurPeak int64 `json:"current_peak"`
}{ }{
Current: l.current, Current: l.current,
CurPeak: l.currentPeak,
Peak: l.peak, Peak: l.peak,
Overall: l.overall, Overall: l.overall})
CurPeak: l.cur_peak})
} }