Merge pull request #116 from joeybloggs/v6-development

V6 development
pull/117/head
Dean Karn 9 years ago
commit 9e60f7d11b
  1. 20
      .travis.yml
  2. 27
      validator.go

@ -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

@ -303,7 +303,7 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
if kind == reflect.Struct { 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 only validating the structs existance.
if strings.Contains(tag, structOnlyTag) { if strings.Contains(tag, structOnlyTag) {
return 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) { 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++ { for i := 0; i < current.Len(); i++ {
v.traverseField(topStruct, currentStruct, current.Index(i), errPrefix, errs, false, tag, fmt.Sprintf(arrayIndexFieldName, name, 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))
} }
} }
@ -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) { 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() { for _, key := range current.MapKeys() {
v.traverseField(topStruct, currentStruct, current.MapIndex(key), errPrefix, errs, false, tag, fmt.Sprintf(mapIndexFieldName, name, key.Interface()))
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()))
} }
} }
// 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 // 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 { 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 { if cTag.isOrVal {
errTag := "" errTag := ""
for _, val := range cTag.tagVals { for _, val := range cTag.tagVals {
valFunc, ok := v.config.ValidationFuncs[val[0]] valFunc, ok = v.config.ValidationFuncs[val[0]]
if !ok { if !ok {
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, name))) panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, name)))
} }
@ -462,7 +451,7 @@ func (v *Validate) validateField(topStruct reflect.Value, currentStruct reflect.
return true return true
} }
valFunc, ok := v.config.ValidationFuncs[cTag.tagVals[0][0]] valFunc, ok = v.config.ValidationFuncs[cTag.tagVals[0][0]]
if !ok { if !ok {
panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, name))) panic(strings.TrimSpace(fmt.Sprintf(undefinedValidation, name)))
} }

Loading…
Cancel
Save