Fix initial traffic value

This commit is contained in:
世界 2024-12-03 21:43:11 +08:00
parent 558585b01d
commit 1e787cb607
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 17 additions and 21 deletions

View file

@ -316,18 +316,15 @@ func traffic(trafficManager *trafficontrol.Manager) func(w http.ResponseWriter,
tick := time.NewTicker(time.Second)
defer tick.Stop()
buf := &bytes.Buffer{}
var (
uploadTotal int64
doanloadTotal int64
err error
)
uploadTotal, downloadTotal := trafficManager.Total()
for range tick.C {
buf.Reset()
uploadTotalNew, downloadTotalNew := trafficManager.Total()
if err := json.NewEncoder(buf).Encode(Traffic{
err := json.NewEncoder(buf).Encode(Traffic{
Up: uploadTotalNew - uploadTotal,
Down: downloadTotalNew - doanloadTotal,
}); err != nil {
Down: downloadTotalNew - downloadTotal,
})
if err != nil {
break
}
if conn == nil {
@ -339,8 +336,9 @@ func traffic(trafficManager *trafficontrol.Manager) func(w http.ResponseWriter,
if err != nil {
break
}
uploadTotal = uploadTotalNew
doanloadTotal = downloadTotalNew
downloadTotal = downloadTotalNew
}
}
}