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 package radio
import ( import (
"encoding/json"
"errors" "errors"
"fmt" "fmt"
"math" "math"
@ -58,3 +59,14 @@ func (l *ListenerCounter) Dec() (int, error) {
l.current-- l.current--
return l.current, nil 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})
}