sshpoke/internal/server/driver/util/validator.go

24 lines
428 B
Go
Raw Normal View History

2023-11-17 20:39:00 +03:00
package util
import (
"regexp"
"github.com/go-playground/validator/v10"
)
var Validator *validator.Validate
func init() {
Validator = validator.New(validator.WithRequiredStructEnabled())
2023-11-17 20:39:00 +03:00
_ = Validator.RegisterValidation("validregexp", isValidRegExp)
}
func isValidRegExp(fl validator.FieldLevel) bool {
expr := fl.Field().String()
if expr == "" {
return true
}
_, err := regexp.Compile(expr)
return err == nil
}