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