mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 20:01:17 +00:00
22 lines
580 B
Go
22 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
|
||
|
}
|
||
|
}
|