From ec5b6a028b5ab7248f85468b340fcfd78b20c613 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Thu, 9 May 2024 20:18:06 +0400 Subject: [PATCH] In ListenerCounter struct int -> int64. --- internal/radio/listener_counter.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/radio/listener_counter.go b/internal/radio/listener_counter.go index e3d3839..dbf51d2 100644 --- a/internal/radio/listener_counter.go +++ b/internal/radio/listener_counter.go @@ -11,7 +11,7 @@ import ( // ListenerCounter stores the current and peak numbers of listeners. type ListenerCounter struct { mutex sync.RWMutex - current, peak int + current, peak int64 } // NewListenerCounter returns a new ListenerCounter struct instance. @@ -20,26 +20,26 @@ func NewListenerCounter() *ListenerCounter { } // Current returns a number of current listeners. -func (l *ListenerCounter) Current() int { +func (l *ListenerCounter) Current() int64 { l.mutex.RLock() defer l.mutex.RUnlock() return l.current } // Current returns a number of peak listeners. -func (l *ListenerCounter) Peak() int { +func (l *ListenerCounter) Peak() int64 { l.mutex.RLock() defer l.mutex.RUnlock() return l.peak } // Inc increments by 1 a current number of listeners and updates a peak number. -func (l *ListenerCounter) Inc() int { +func (l *ListenerCounter) Inc() int64 { l.mutex.Lock() defer l.mutex.Unlock() - if l.current == math.MaxInt { + if l.current == math.MaxInt64 { // We panic here because if this will ever happen, then something's going certainly wrong. - panic(fmt.Sprint("a current number of listeners exceeded MaxInt which is", math.MaxInt)) + panic(fmt.Sprint("a current number of listeners exceeded MaxInt64 which is", math.MaxInt)) } l.current++ if l.current > l.peak { @@ -50,7 +50,7 @@ func (l *ListenerCounter) Inc() int { // Dec decrements by 1 a current number of listeners. An error will occur if // a resulting number is less than 0. -func (l *ListenerCounter) Dec() (int, error) { +func (l *ListenerCounter) Dec() (int64, error) { l.mutex.Lock() defer l.mutex.Unlock() if l.current == 0 { @@ -64,8 +64,8 @@ func (l *ListenerCounter) MarshalJSON() ([]byte, error) { l.mutex.RLock() defer l.mutex.RUnlock() return json.Marshal(&struct { - Current int `json:"current"` - Peak int `json:"peak"` + Current int64 `json:"current"` + Peak int64 `json:"peak"` }{ Current: l.current, Peak: l.peak})