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