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)
}
ret = string(valueByte)
for {
if len(ret) <= contextValueLen {
break
}
for len(ret) > contextValueLen {
// if there is only 1 value left and that the size is too big, truncate it
if len(values) == 1 {
valueToTruncate := values[0]

View file

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