twitch-bot/internal/helpers/validateHelper.go
Knut Ahlers 30482591a7
[core] Switch to go_helpers FieldCollection
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2024-04-07 13:37:13 +02:00

21 lines
580 B
Go

package helpers
import (
"fmt"
"github.com/Luzifer/go_helpers/v2/fieldcollection"
)
// SchemaValidateTemplateField contains a ValidateOpt for the
// fieldcollection schema validator to validate template fields
func SchemaValidateTemplateField(tplValidator func(string) error, fields ...string) fieldcollection.ValidateOpt {
return func(f, _ *fieldcollection.FieldCollection) (err error) {
for _, field := range fields {
if err = tplValidator(f.MustString(field, Ptr(""))); err != nil {
return fmt.Errorf("validating %s: %w", field, err)
}
}
return nil
}
}