Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

27 changes: 8 additions & 19 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.

if kind == reflect.Struct {

// required passed validationa above so stop here
// required passed validation above so stop here
// if only validating the structs existance.
if strings.Contains(tag, structOnlyTag) {
return
Expand Down Expand Up @@ -404,42 +404,31 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
func (v *Validate) traverseSlice(topStruct reflect.Value, currentStruct reflect.Value, current reflect.Value, errPrefix string, errs ValidationErrors, tag string, name string) {

for i := 0; i < current.Len(); i++ {

idxField := current.Index(i)

if idxField.Kind() == reflect.Ptr && !idxField.IsNil() {
idxField = idxField.Elem()
}

v.traverseField(topStruct, currentStruct, idxField, errPrefix, errs, false, tag, fmt.Sprintf(arrayIndexFieldName, name, i))
v.traverseField(topStruct, currentStruct, current.Index(i), errPrefix, errs, false, tag, fmt.Sprintf(arrayIndexFieldName, name, i))
}
}

// traverseMap traverses a map's elements and passes them to traverseField for validation
func (v *Validate) traverseMap(topStruct reflect.Value, currentStruct reflect.Value, current reflect.Value, errPrefix string, errs ValidationErrors, tag string, name string) {

for _, key := range current.MapKeys() {

idxField := current.MapIndex(key)

if idxField.Kind() == reflect.Ptr && !idxField.IsNil() {
idxField = idxField.Elem()
}

v.traverseField(topStruct, currentStruct, idxField, errPrefix, errs, false, tag, fmt.Sprintf(mapIndexFieldName, name, key.Interface()))
v.traverseField(topStruct, currentStruct, current.MapIndex(key), errPrefix, errs, false, tag, fmt.Sprintf(mapIndexFieldName, name, key.Interface()))
}
}

// validateField validates a field based on the provided tag's key and param values and returns true if there is an error or false if all ok
func (v *Validate) validateField(topStruct reflect.Value, currentStruct reflect.Value, current reflect.Value, currentType reflect.Type, currentKind reflect.Kind, errPrefix string, errs ValidationErrors, cTag *tagCache, name string) bool {

var valFunc Func
var ok bool

if cTag.isOrVal {

errTag := ""

for _, val := range cTag.tagVals {

valFunc, ok := v.config.ValidationFuncs[val[0]]
valFunc, ok = v.config.ValidationFuncs[val[0]]
if !ok {
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, name)))
}
Expand All @@ -462,7 +451,7 @@ func (v *Validate) validateField(topStruct reflect.Value, currentStruct reflect.
return true
}

valFunc, ok := v.config.ValidationFuncs[cTag.tagVals[0][0]]
valFunc, ok = v.config.ValidationFuncs[cTag.tagVals[0][0]]
if !ok {
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, name)))
}
Expand Down