For ListenerCounter implemented MarshalJSON() method.
This commit is contained in:
parent
2be516236b
commit
381da691a4
@ -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})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user