Skip to content

Commit

Permalink
change codes bool value to struct{}
Browse files Browse the repository at this point in the history
Closes #1269
  • Loading branch information
nar10z committed May 27, 2024
1 parent e20b948 commit b987593
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 @@ -2768,26 +2768,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 @@ -2809,7 +2809,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 @@ -2831,19 +2833,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 @@ -2859,7 +2863,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 b987593

Please sign in to comment.