mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
fix data race for system info
This commit is contained in:
parent
767560804d
commit
8114b04ab6
1 changed files with 2 additions and 13 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/cpu"
|
||||
|
@ -97,12 +96,6 @@ var allQueries = []string{
|
|||
|
||||
var Poller = period.NewPoller("system_info", getSystemInfo, aggregate)
|
||||
|
||||
var bufPool = sync.Pool{
|
||||
New: func() any {
|
||||
return bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Poller.Start()
|
||||
}
|
||||
|
@ -293,9 +286,7 @@ func (s *SystemInfo) collectSensorsInfo(ctx context.Context) error {
|
|||
|
||||
// explicitly implement MarshalJSON to avoid reflection
|
||||
func (s *SystemInfo) MarshalJSON() ([]byte, error) {
|
||||
b := bufPool.Get().(*bytes.Buffer)
|
||||
b.Reset()
|
||||
defer bufPool.Put(b)
|
||||
b := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
b.WriteRune('{')
|
||||
|
||||
|
@ -561,9 +552,7 @@ func aggregate(entries []*SystemInfo, query url.Values) (total int, result Aggre
|
|||
}
|
||||
|
||||
func (result Aggregated) MarshalJSON() ([]byte, error) {
|
||||
buf := bufPool.Get().(*bytes.Buffer)
|
||||
buf.Reset()
|
||||
defer bufPool.Put(buf)
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
buf.WriteByte('[')
|
||||
i := 0
|
||||
|
|
Loading…
Add table
Reference in a new issue