|
|
@ -5,7 +5,6 @@ import ( |
|
|
|
"net" |
|
|
|
"net" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"reflect" |
|
|
|
"reflect" |
|
|
|
"strconv" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
"unicode/utf8" |
|
|
|
"unicode/utf8" |
|
|
@ -27,6 +26,7 @@ var BakedInValidators = map[string]Func{ |
|
|
|
"gte": isGte, |
|
|
|
"gte": isGte, |
|
|
|
"eqfield": isEqField, |
|
|
|
"eqfield": isEqField, |
|
|
|
"eqcsfield": isEqCrossStructField, |
|
|
|
"eqcsfield": isEqCrossStructField, |
|
|
|
|
|
|
|
"necsfield": isNeCrossStructField, |
|
|
|
"nefield": isNeField, |
|
|
|
"nefield": isNeField, |
|
|
|
"gtefield": isGteField, |
|
|
|
"gtefield": isGteField, |
|
|
|
"gtfield": isGtField, |
|
|
|
"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) |
|
|
|
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 { |
|
|
|
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) |
|
|
|
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) |
|
|
|
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()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|