package common import ( "math" "github.com/gogf/gf/v2/errors/gerror" ) func validateTrafficCutoffConfig(status int, threshold float64) error { if status < 0 || status > 2 { return gerror.New("达量断网配置状态无效") } if threshold < 0 { return gerror.New("达量断网阈值不能小于0") } if status == 0 && threshold != 0 { return gerror.New("未配置达量断网时阈值必须为0") } if status == 1 && threshold <= 0 { return gerror.New("开启达量断网时阈值必须大于0") } rounded := math.Round(threshold*1000) / 1000 if math.Abs(threshold-rounded) > 0.0000001 { return gerror.New("达量断网阈值最多保留3位小数") } return nil }