Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up input parameters in requireCheckFieldKind #1347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions baked_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -1797,19 +1797,19 @@ func hasValue(fl FieldLevel) bool {
}

// requireCheckFieldKind is a func for check field kind
func requireCheckFieldKind(fl FieldLevel, param string, defaultNotFoundValue bool) bool {
func requireCheckFieldKind(fl FieldLevel, param string) bool {
field := fl.Field()
kind := field.Kind()
var nullable, found bool
if len(param) > 0 {
field, kind, nullable, found = fl.GetStructFieldOKAdvanced2(fl.Parent(), param)
if !found {
return defaultNotFoundValue
return true
}
}
switch kind {
case reflect.Invalid:
return defaultNotFoundValue
return true
case reflect.Slice, reflect.Map, reflect.Ptr, reflect.Interface, reflect.Chan, reflect.Func:
return field.IsNil()
default:
Expand Down Expand Up @@ -1943,7 +1943,7 @@ func excludedUnless(fl FieldLevel) bool {
func excludedWith(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
for _, param := range params {
if !requireCheckFieldKind(fl, param, true) {
if !requireCheckFieldKind(fl, param) {
return !hasValue(fl)
}
}
Expand All @@ -1955,7 +1955,7 @@ func excludedWith(fl FieldLevel) bool {
func requiredWith(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
for _, param := range params {
if !requireCheckFieldKind(fl, param, true) {
if !requireCheckFieldKind(fl, param) {
return hasValue(fl)
}
}
Expand All @@ -1967,7 +1967,7 @@ func requiredWith(fl FieldLevel) bool {
func excludedWithAll(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
for _, param := range params {
if requireCheckFieldKind(fl, param, true) {
if requireCheckFieldKind(fl, param) {
return true
}
}
Expand All @@ -1979,7 +1979,7 @@ func excludedWithAll(fl FieldLevel) bool {
func requiredWithAll(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
for _, param := range params {
if requireCheckFieldKind(fl, param, true) {
if requireCheckFieldKind(fl, param) {
return true
}
}
Expand All @@ -1989,7 +1989,7 @@ func requiredWithAll(fl FieldLevel) bool {
// excludedWithout is the validation function
// The field under validation must not be present or is empty when any of the other specified fields are not present.
func excludedWithout(fl FieldLevel) bool {
if requireCheckFieldKind(fl, strings.TrimSpace(fl.Param()), true) {
if requireCheckFieldKind(fl, strings.TrimSpace(fl.Param())) {
return !hasValue(fl)
}
return true
Expand All @@ -1998,7 +1998,7 @@ func excludedWithout(fl FieldLevel) bool {
// requiredWithout is the validation function
// The field under validation must be present and not empty only when any of the other specified fields are not present.
func requiredWithout(fl FieldLevel) bool {
if requireCheckFieldKind(fl, strings.TrimSpace(fl.Param()), true) {
if requireCheckFieldKind(fl, strings.TrimSpace(fl.Param())) {
return hasValue(fl)
}
return true
Expand All @@ -2009,7 +2009,7 @@ func requiredWithout(fl FieldLevel) bool {
func excludedWithoutAll(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
for _, param := range params {
if !requireCheckFieldKind(fl, param, true) {
if !requireCheckFieldKind(fl, param) {
return true
}
}
Expand All @@ -2021,7 +2021,7 @@ func excludedWithoutAll(fl FieldLevel) bool {
func requiredWithoutAll(fl FieldLevel) bool {
params := parseOneOfParam2(fl.Param())
for _, param := range params {
if !requireCheckFieldKind(fl, param, true) {
if !requireCheckFieldKind(fl, param) {
return true
}
}
Expand Down
Loading