|
@@ -14,9 +14,9 @@ var (
|
|
|
ERequired = errors.New("this field is required")
|
|
|
)
|
|
|
|
|
|
-// validLettersGeneric is a validator generator for checking
|
|
|
+// ValidLettersGeneric is a validator generator for checking
|
|
|
// for valid letters in field
|
|
|
-func validLettersGeneric(Letters string, Error error) ValidatorFunc {
|
|
|
+func ValidLettersGeneric(Letters string, Error error) ValidatorFunc {
|
|
|
Callback := func(field FormField, ctx context.Context) error {
|
|
|
for _, Rune := range field.GetString() {
|
|
|
if strings.IndexRune(Letters, Rune) == -1 {
|
|
@@ -28,18 +28,18 @@ func validLettersGeneric(Letters string, Error error) ValidatorFunc {
|
|
|
return Callback
|
|
|
}
|
|
|
|
|
|
-// validRequired returns nil if there is text in the field.
|
|
|
+// ValidRequired returns nil if there is text in the field.
|
|
|
// If the field is empty it returns error.
|
|
|
-func validRequired(field FormField, ctx context.Context) error {
|
|
|
+func ValidRequired(field FormField, ctx context.Context) error {
|
|
|
if field.GetString() == "" {
|
|
|
return ERequired
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// validLength returns a string field validator that verifies if a string
|
|
|
+// ValidLength returns a string field validator that verifies if a string
|
|
|
// length is between specified min and max values.
|
|
|
-func validLength(min, max int) ValidatorFunc {
|
|
|
+func ValidLength(min, max int) ValidatorFunc {
|
|
|
var ELength = errors.New(
|
|
|
fmt.Sprintf("must be a string between %d and %d characters in length", min, max))
|
|
|
return func(field FormField, ctx context.Context) error {
|
|
@@ -50,8 +50,8 @@ func validLength(min, max int) ValidatorFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// validFieldIn verifies if item is within the list of items
|
|
|
-func validFieldIn(list []string) ValidatorFunc {
|
|
|
+// ValidFieldIn verifies if item is within the list of items
|
|
|
+func ValidFieldIn(list []string) ValidatorFunc {
|
|
|
var EInvalidValue = errors.New(
|
|
|
fmt.Sprintf(
|
|
|
"field value must be one of: %s",
|
|
@@ -68,8 +68,8 @@ func validFieldIn(list []string) ValidatorFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// validInt returns error if field does not contain a valid integer value
|
|
|
-func validInt(field FormField, ctx context.Context) error {
|
|
|
+// ValidInt returns error if field does not contain a valid integer value
|
|
|
+func ValidInt(field FormField, ctx context.Context) error {
|
|
|
_, err := field.GetInt()
|
|
|
if err != nil {
|
|
|
return EInvalidInteger
|
|
@@ -77,9 +77,9 @@ func validInt(field FormField, ctx context.Context) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// validBetween is a validator generator that makes sure field is
|
|
|
+// ValidBetween is a validator generator that makes sure field is
|
|
|
// integer value within the specified range.
|
|
|
-func validBetween(min, max int) ValidatorFunc {
|
|
|
+func ValidBetween(min, max int) ValidatorFunc {
|
|
|
var EInvalidInterval = errors.New(
|
|
|
fmt.Sprintf("must be integer between %d and %d", min, max))
|
|
|
return func(field FormField, ctx context.Context) error {
|
|
@@ -94,8 +94,8 @@ func validBetween(min, max int) ValidatorFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// validFloat returns error if field does not contain a valid integer value
|
|
|
-func validFloat(field FormField, ctx context.Context) error {
|
|
|
+// ValidFloat returns error if field does not contain a valid integer value
|
|
|
+func ValidFloat(field FormField, ctx context.Context) error {
|
|
|
_, err := field.GetFloat()
|
|
|
if err != nil {
|
|
|
return EInvalidFloat
|
|
@@ -103,9 +103,9 @@ func validFloat(field FormField, ctx context.Context) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// validBetweenFloat32 is a v alidator generator that makes sure field is
|
|
|
+// ValidBetweenFloat32 is a v alidator generator that makes sure field is
|
|
|
// float64 value within the specified range.
|
|
|
-func validBetweenFloat(min, max float64) ValidatorFunc {
|
|
|
+func ValidBetweenFloat(min, max float64) ValidatorFunc {
|
|
|
var EInvalidInterval = errors.New(
|
|
|
fmt.Sprintf("must be float value between %.2f and %.2f", min, max))
|
|
|
return func(field FormField, ctx context.Context) error {
|
|
@@ -120,9 +120,9 @@ func validBetweenFloat(min, max float64) ValidatorFunc {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// validFieldEqualTo is a general purpose validator that checks
|
|
|
+// ValidFieldEqualTo is a general purpose validator that checks
|
|
|
// if two fields have the same value for verification purposes.
|
|
|
-func validFieldEqualTo(Other *FormField, err error) ValidatorFunc {
|
|
|
+func ValidFieldEqualTo(Other *FormField, err error) ValidatorFunc {
|
|
|
return func(field FormField, ctx context.Context) error {
|
|
|
if field.GetString() != Other.GetString() {
|
|
|
return err
|