simplify a couple loops

This commit is contained in:
marco 2024-04-29 15:22:38 +02:00
parent 05b54687b6
commit 26faf6fb13
2 changed files with 12 additions and 17 deletions

View file

@ -91,10 +91,7 @@ func truncate(values []string, contextValueLen int) (string, error) {
return "", fmt.Errorf("unable to dump metas: %s", err) return "", fmt.Errorf("unable to dump metas: %s", err)
} }
ret = string(valueByte) ret = string(valueByte)
for { for len(ret) > contextValueLen {
if len(ret) <= contextValueLen {
break
}
// if there is only 1 value left and that the size is too big, truncate it // if there is only 1 value left and that the size is too big, truncate it
if len(values) == 1 { if len(values) == 1 {
valueToTruncate := values[0] valueToTruncate := values[0]

View file

@ -380,19 +380,17 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {
bucketFactory.processors = append(bucketFactory.processors, &BayesianBucket{}) bucketFactory.processors = append(bucketFactory.processors, &BayesianBucket{})
} }
if len(bucketFactory.Data) > 0 { for _, data := range bucketFactory.Data {
for _, data := range bucketFactory.Data { if data.DestPath == "" {
if data.DestPath == "" { bucketFactory.logger.Errorf("no dest_file provided for '%s'", bucketFactory.Name)
bucketFactory.logger.Errorf("no dest_file provided for '%s'", bucketFactory.Name) continue
continue }
} err = exprhelpers.FileInit(bucketFactory.DataDir, data.DestPath, data.Type)
err = exprhelpers.FileInit(bucketFactory.DataDir, data.DestPath, data.Type) if err != nil {
if err != nil { bucketFactory.logger.Errorf("unable to init data for file '%s': %s", data.DestPath, err)
bucketFactory.logger.Errorf("unable to init data for file '%s': %s", data.DestPath, err) }
} if data.Type == "regexp" { //cache only makes sense for regexp
if data.Type == "regexp" { //cache only makes sense for regexp exprhelpers.RegexpCacheInit(data.DestPath, *data)
exprhelpers.RegexpCacheInit(data.DestPath, *data)
}
} }
} }