mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:08:31 +02:00
fix(uptime): set to 0 instead of returning error on overflow check
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -37,11 +36,13 @@ func (info *HealthInfo) UnmarshalJSON(data []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// overflow check
|
// overflow check
|
||||||
if math.MaxInt64/time.Microsecond < time.Duration(v.Latency) {
|
// Check if latency (in microseconds) would overflow when converted to nanoseconds
|
||||||
return fmt.Errorf("latency overflow: %d", v.Latency)
|
if v.Latency > math.MaxInt64/int64(time.Microsecond) {
|
||||||
|
v.Latency = 0
|
||||||
}
|
}
|
||||||
if math.MaxInt64/time.Millisecond < time.Duration(v.Uptime) {
|
// Check if uptime (in milliseconds) would overflow when converted to nanoseconds
|
||||||
return fmt.Errorf("uptime overflow: %d", v.Uptime)
|
if v.Uptime > math.MaxInt64/int64(time.Millisecond) {
|
||||||
|
v.Uptime = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
info.Status = types.NewHealthStatusFromString(v.Status)
|
info.Status = types.NewHealthStatusFromString(v.Status)
|
||||||
|
|||||||
Reference in New Issue
Block a user