Checks if field value matches regex. If fl.Field can be cast to Stringer, it uses the Stringer interfaces String() return value. Otherwise, it uses fl.Field's String() value.
(regexFn func() *regexp.Regexp, fl FieldLevel)
| 321 | // Checks if field value matches regex. If fl.Field can be cast to Stringer, it uses the Stringer interfaces |
| 322 | // String() return value. Otherwise, it uses fl.Field's String() value. |
| 323 | func fieldMatchesRegexByStringerValOrString(regexFn func() *regexp.Regexp, fl FieldLevel) bool { |
| 324 | regex := regexFn() |
| 325 | switch fl.Field().Kind() { |
| 326 | case reflect.String: |
| 327 | return regex.MatchString(fl.Field().String()) |
| 328 | default: |
| 329 | if stringer, ok := getValue(fl.Field()).(fmt.Stringer); ok { |
| 330 | return regex.MatchString(stringer.String()) |
| 331 | } else { |
| 332 | return regex.MatchString(fl.Field().String()) |
| 333 | } |
| 334 | } |
| 335 | } |
no test coverage detected
searching dependent graphs…