From 347979cec79be83d931a42c21d3485ee846f8f4b Mon Sep 17 00:00:00 2001 From: Dean Karn Date: Sun, 19 Jul 2015 12:07:01 -0400 Subject: [PATCH 1/2] Delete .travis.yml no longer needed changed CI to semaphore --- .travis.yml | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 389db22..0000000 --- a/.travis.yml +++ /dev/null @@ -1,20 +0,0 @@ -language: go - -notificaitons: - email: - recipients: bluesuncorp01@gmail.com - on_success: change - on_failure: always - -go: - - 1.3 - - 1.4 - - tip - -script: - - go get golang.org/x/tools/cmd/cover - - go get github.com/mattn/goveralls - - go test -v -covermode=count -coverprofile=cover.out - -after_success: - - goveralls -coverprofile=cover.out -service=travis-ci -repotoken I6M8FiXZzErImgwMotJ7fwFlHOX8Hqdq1 \ No newline at end of file From 2baa4bd3535434e7679808385ac2752a332ac59d Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Sun, 19 Jul 2015 21:39:58 -0400 Subject: [PATCH 2/2] Minor code cleanup --- validator.go | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/validator.go b/validator.go index 6c44f2b..6a527b2 100644 --- a/validator.go +++ b/validator.go @@ -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 @@ -404,14 +404,7 @@ 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)) } } @@ -419,27 +412,23 @@ func (v *Validate) traverseSlice(topStruct reflect.Value, currentStruct reflect. 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))) } @@ -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))) }