Skip to content

Commit 10c3c84

Browse files
authored
change codes bool value to struct{} (#1270)
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
1 parent ab370b6 commit 10c3c84

File tree

3 files changed

+1255
-1249
lines changed

3 files changed

+1255
-1249
lines changed

baked_in.go

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2769,26 +2769,26 @@ func isTimeZone(fl FieldLevel) bool {
27692769

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

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

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

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

27942794
// isIso3166AlphaNumeric is the validation function for validating if the current field's value is a valid iso3166-1 alpha-numeric country code.
@@ -2810,7 +2810,9 @@ func isIso3166AlphaNumeric(fl FieldLevel) bool {
28102810
default:
28112811
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
28122812
}
2813-
return iso3166_1_alpha_numeric[code]
2813+
2814+
_, ok := iso3166_1_alpha_numeric[code]
2815+
return ok
28142816
}
28152817

28162818
// isIso3166AlphaNumericEU is the validation function for validating if the current field's value is a valid iso3166-1 alpha-numeric European Union country code.
@@ -2832,19 +2834,21 @@ func isIso3166AlphaNumericEU(fl FieldLevel) bool {
28322834
default:
28332835
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
28342836
}
2835-
return iso3166_1_alpha_numeric_eu[code]
2837+
2838+
_, ok := iso3166_1_alpha_numeric_eu[code]
2839+
return ok
28362840
}
28372841

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

28442848
// isIso4217 is the validation function for validating if the current field's value is a valid iso4217 currency code.
28452849
func isIso4217(fl FieldLevel) bool {
2846-
val := fl.Field().String()
2847-
return iso4217[val]
2850+
_, ok := iso4217[fl.Field().String()]
2851+
return ok
28482852
}
28492853

28502854
// isIso4217Numeric is the validation function for validating if the current field's value is a valid iso4217 numeric currency code.
@@ -2860,7 +2864,9 @@ func isIso4217Numeric(fl FieldLevel) bool {
28602864
default:
28612865
panic(fmt.Sprintf("Bad field type %T", field.Interface()))
28622866
}
2863-
return iso4217_numeric[code]
2867+
2868+
_, ok := iso4217_numeric[code]
2869+
return ok
28642870
}
28652871

28662872
// 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

0 commit comments

Comments
 (0)