Merge pull request #493 from xixingya/feature/bug-fix

ratio must gte 0
This commit is contained in:
Calcium-Ion
2024-11-19 18:34:24 +08:00
committed by GitHub
3 changed files with 32 additions and 1 deletions

View File

@@ -2,6 +2,7 @@ package common
import (
"encoding/json"
"errors"
)
var GroupRatio = map[string]float64{
@@ -31,3 +32,17 @@ func GetGroupRatio(name string) float64 {
}
return ratio
}
func CheckGroupRatio(jsonStr string) error {
checkGroupRatio := make(map[string]float64)
err := json.Unmarshal([]byte(jsonStr), &checkGroupRatio)
if err != nil {
return err
}
for name, ratio := range checkGroupRatio {
if ratio < 0 {
return errors.New("group ratio must be not less than 0: " + name)
}
}
return nil
}