Skip to content

Commit

Permalink
change codes bool value to struct{} (#1270)
Browse files Browse the repository at this point in the history
Closes #1269

## Fixes Or Enhances


**Make sure that you've checked the boxes below before you submit PR:**
- [ ] Tests exist or have been written that cover this particular
change.

@go-playground/validator-maintainers
  • Loading branch information
nar10z authored Jun 1, 2024
1 parent ab370b6 commit 10c3c84
Show file tree
Hide file tree
Showing 3 changed files with 1,255 additions and 1,249 deletions.
36 changes: 21 additions & 15 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -2769,26 +2769,26 @@ func isTimeZone(fl FieldLevel) bool {

// isIso3166Alpha2 is the validation function for validating if the current field's value is a valid iso3166-1 alpha-2 country code.
func isIso3166Alpha2(fl FieldLevel) bool {
val := fl.Field().String()
return iso3166_1_alpha2[val]
_, ok := iso3166_1_alpha2[fl.Field().String()]
return ok
}

// isIso3166Alpha2EU is the validation function for validating if the current field's value is a valid iso3166-1 alpha-2 European Union country code.
func isIso3166Alpha2EU(fl FieldLevel) bool {
val := fl.Field().String()
return iso3166_1_alpha2_eu[val]
_, ok := iso3166_1_alpha2_eu[fl.Field().String()]
return ok
}

// isIso3166Alpha3 is the validation function for validating if the current field's value is a valid iso3166-1 alpha-3 country code.
func isIso3166Alpha3(fl FieldLevel) bool {
val := fl.Field().String()
return iso3166_1_alpha3[val]
_, ok := iso3166_1_alpha3[fl.Field().String()]
return ok
}

// isIso3166Alpha3EU is the validation function for validating if the current field's value is a valid iso3166-1 alpha-3 European Union country code.
func isIso3166Alpha3EU(fl FieldLevel) bool {
val := fl.Field().String()
return iso3166_1_alpha3_eu[val]
_, ok := iso3166_1_alpha3_eu[fl.Field().String()]
return ok
}

// isIso3166AlphaNumeric is the validation function for validating if the current field's value is a valid iso3166-1 alpha-numeric country code.
Expand All @@ -2810,7 +2810,9 @@ func isIso3166AlphaNumeric(fl FieldLevel) bool {
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
return iso3166_1_alpha_numeric[code]

_, ok := iso3166_1_alpha_numeric[code]
return ok
}

// isIso3166AlphaNumericEU is the validation function for validating if the current field's value is a valid iso3166-1 alpha-numeric European Union country code.
Expand All @@ -2832,19 +2834,21 @@ func isIso3166AlphaNumericEU(fl FieldLevel) bool {
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
return iso3166_1_alpha_numeric_eu[code]

_, ok := iso3166_1_alpha_numeric_eu[code]
return ok
}

// isIso31662 is the validation function for validating if the current field's value is a valid iso3166-2 code.
func isIso31662(fl FieldLevel) bool {
val := fl.Field().String()
return iso3166_2[val]
_, ok := iso3166_2[fl.Field().String()]
return ok
}

// isIso4217 is the validation function for validating if the current field's value is a valid iso4217 currency code.
func isIso4217(fl FieldLevel) bool {
val := fl.Field().String()
return iso4217[val]
_, ok := iso4217[fl.Field().String()]
return ok
}

// isIso4217Numeric is the validation function for validating if the current field's value is a valid iso4217 numeric currency code.
Expand All @@ -2860,7 +2864,9 @@ func isIso4217Numeric(fl FieldLevel) bool {
default:
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
}
return iso4217_numeric[code]

_, ok := iso4217_numeric[code]
return ok
}

// isBCP47LanguageTag is the validation function for validating if the current field's value is a valid BCP 47 language tag, as parsed by language.Parse
Expand Down
Loading

0 comments on commit 10c3c84

Please sign in to comment.