1
0

For ListenerCounter implemented MarshalJSON() method.

This commit is contained in:
Alexander Andreev 2023-10-01 22:03:26 +04:00
parent 2be516236b
commit 381da691a4
Signed by: Arav
GPG Key ID: D22A817D95815393

View File

@ -1,6 +1,7 @@
package radio
import (
"encoding/json"
"errors"
"fmt"
"math"
@ -58,3 +59,14 @@ func (l *ListenerCounter) Dec() (int, error) {
l.current--
return l.current, nil
}
func (l *ListenerCounter) MarshalJSON() ([]byte, error) {
l.mut.Lock()
defer l.mut.Unlock()
return json.Marshal(&struct {
Current int `json:"current"`
Peak int `json:"peak"`
}{
Current: l.current,
Peak: l.peak})
}