refactored logic

This commit is contained in:
0xdcarns
2021-10-26 12:27:29 -04:00
parent d25cc93598
commit 8f72ecbaa0
33 changed files with 985 additions and 1092 deletions

18
validation/validation.go Normal file
View File

@@ -0,0 +1,18 @@
package validation
import (
"regexp"
"github.com/go-playground/validator/v10"
)
// CheckYesOrNo - checks if a field on a struct is yes or no
func CheckYesOrNo(fl validator.FieldLevel) bool {
return fl.Field().String() == "yes" || fl.Field().String() == "no"
}
// CheckRegex - check if a struct's field passes regex test
func CheckRegex(fl validator.FieldLevel) bool {
re := regexp.MustCompile(fl.Param())
return re.MatchString(fl.Field().String())
}