|
|
|
@ -5,7 +5,6 @@ import ( |
|
|
|
|
"net" |
|
|
|
|
"net/url" |
|
|
|
|
"reflect" |
|
|
|
|
"strconv" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
"unicode/utf8" |
|
|
|
@ -27,6 +26,7 @@ var BakedInValidators = map[string]Func{ |
|
|
|
|
"gte": isGte, |
|
|
|
|
"eqfield": isEqField, |
|
|
|
|
"eqcsfield": isEqCrossStructField, |
|
|
|
|
"necsfield": isNeCrossStructField, |
|
|
|
|
"nefield": isNeField, |
|
|
|
|
"gtefield": isGteField, |
|
|
|
|
"gtfield": isGtField, |
|
|
|
@ -254,6 +254,11 @@ func isNe(v *Validate, topStruct reflect.Value, currentStruct reflect.Value, fie |
|
|
|
|
return !isEq(v, topStruct, currentStruct, field, fieldType, fieldKind, param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isNeCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { |
|
|
|
|
|
|
|
|
|
return !isEqCrossStructField(v, topStruct, current, field, fieldType, fieldKind, param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func isEqCrossStructField(v *Validate, topStruct reflect.Value, current reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) bool { |
|
|
|
|
|
|
|
|
|
topField, topKind, ok := v.getStructFieldOK(topStruct, param) |
|
|
|
@ -842,39 +847,3 @@ func hasMaxOf(v *Validate, topStruct reflect.Value, currentStruct reflect.Value, |
|
|
|
|
|
|
|
|
|
return isLte(v, topStruct, currentStruct, field, fieldType, fieldKind, param) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// asInt retuns the parameter as a int64
|
|
|
|
|
// or panics if it can't convert
|
|
|
|
|
func asInt(param string) int64 { |
|
|
|
|
|
|
|
|
|
i, err := strconv.ParseInt(param, 0, 64) |
|
|
|
|
panicIf(err) |
|
|
|
|
|
|
|
|
|
return i |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// asUint returns the parameter as a uint64
|
|
|
|
|
// or panics if it can't convert
|
|
|
|
|
func asUint(param string) uint64 { |
|
|
|
|
|
|
|
|
|
i, err := strconv.ParseUint(param, 0, 64) |
|
|
|
|
panicIf(err) |
|
|
|
|
|
|
|
|
|
return i |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// asFloat returns the parameter as a float64
|
|
|
|
|
// or panics if it can't convert
|
|
|
|
|
func asFloat(param string) float64 { |
|
|
|
|
|
|
|
|
|
i, err := strconv.ParseFloat(param, 64) |
|
|
|
|
panicIf(err) |
|
|
|
|
|
|
|
|
|
return i |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func panicIf(err error) { |
|
|
|
|
if err != nil { |
|
|
|
|
panic(err.Error()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|