Skip to content

Commit b987593

Browse files
committed
change codes bool value to struct{}
Closes #1269
1 parent e20b948 commit b987593

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
@@ -2768,26 +2768,26 @@ func isTimeZone(fl FieldLevel) bool {
27682768

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

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

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

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

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

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

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

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

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

28652871
// 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)