handle negative values, fix 1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
2025-04-09 13:07:28 +02:00
parent 53dc8a68a3
commit a0733f70e5

View File

@ -56,6 +56,9 @@ func calculateDifference(key string, newValue string) (string, error) {
Timestamp: currentTime,
Value: newValue,
}
if diffValuePerSecond < 0 {
return "", fmt.Errorf("negative difference value: %d", diffValuePerSecond)
}
return strconv.Itoa(diffValuePerSecond), nil
} else {
log.Printf("create lvv for %s", key)
@ -122,8 +125,6 @@ func Start() {
if err != nil {
log.Printf("Error when building difference: %v", err)
convertedValue = "-1"
} else if diff < 0 {
convertedValue = "-2"
} else {
convertedValue = diff
}