@ -13,9 +13,9 @@ import (
// or even disregard and use your own map if so desired.
// or even disregard and use your own map if so desired.
var BakedInValidators = map [ string ] Func {
var BakedInValidators = map [ string ] Func {
"required" : hasValue ,
"required" : hasValue ,
// "len": hasLengthOf,
"len" : hasLengthOf ,
"min" : hasMinOf ,
"min" : hasMinOf ,
"max" : hasMaxOf ,
"max" : hasMaxOf ,
// "eq": isEq,
// "eq": isEq,
// "ne": isNe,
// "ne": isNe,
// "lt": isLt,
// "lt": isLt,
@ -621,7 +621,7 @@ func isGte(topStruct reflect.Value, currentStruct reflect.Value, field reflect.V
}
}
}
}
panic ( fmt . Sprintf ( "Bad field type %T" , field ) )
panic ( fmt . Sprintf ( "Bad field type %T" , field . Interface ( ) ) )
}
}
// func isGt(top interface{}, current interface{}, field interface{}, param string) bool {
// func isGt(top interface{}, current interface{}, field interface{}, param string) bool {
@ -665,43 +665,41 @@ func isGte(topStruct reflect.Value, currentStruct reflect.Value, field reflect.V
// panic(fmt.Sprintf("Bad field type %T", field))
// panic(fmt.Sprintf("Bad field type %T", field))
// }
// }
// // length tests whether a variable's length is equal to a given
// length tests whether a variable's length is equal to a given
// // value. For strings it tests the number of characters whereas
// value. For strings it tests the number of characters whereas
// // for maps and slices it tests the number of items.
// for maps and slices it tests the number of items.
// func hasLengthOf(top interface{}, current interface{}, field interface{}, param string) bool {
func hasLengthOf ( topStruct reflect . Value , currentStruct reflect . Value , field reflect . Value , fieldType reflect . Type , fieldKind reflect . Kind , param string ) bool {
// st := reflect.ValueOf(field)
switch fieldKind {
// switch st.Kind() {
case reflect . String :
p := asInt ( param )
// case reflect.String:
return int64 ( utf8 . RuneCountInString ( field . String ( ) ) ) == p
// p := asInt(param)
// return int64(utf8.RuneCountInString(st.String())) == p
case reflect . Slice , reflect . Map , reflect . Array :
p := asInt ( param )
// case reflect.Slice, reflect.Map, reflect.Array:
return int64 ( field . Len ( ) ) == p
// p := asInt(param)
// return int64(st.Len()) == p
case reflect . Int , reflect . Int8 , reflect . Int16 , reflect . Int32 , reflect . Int64 :
p := asInt ( param )
// case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return field . Int ( ) == p
// p := asInt(param)
// return st.Int() == p
case reflect . Uint , reflect . Uint8 , reflect . Uint16 , reflect . Uint32 , reflect . Uint64 , reflect . Uintptr :
p := asUint ( param )
// case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
// p := asUint(param)
// return st.Uint() == p
return field . Uint ( ) == p
// case reflect.Float32, reflect.Float64:
case reflect . Float32 , reflect . Float64 :
// p := asFloat(param)
p := asFloat ( param )
// return st.Float() == p
return field . Float ( ) == p
// }
}
// panic(fmt.Sprintf("Bad field type %T", field))
panic ( fmt . Sprintf ( "Bad field type %T" , field . Interface ( ) ) )
// }
}
// min tests whether a variable value is larger or equal to a given
// min tests whether a variable value is larger or equal to a given
// number. For number types, it's a simple lesser-than test; for
// number. For number types, it's a simple lesser-than test; for
@ -902,7 +900,7 @@ func isLte(topStruct reflect.Value, currentStruct reflect.Value, field reflect.V
}
}
}
}
panic ( fmt . Sprintf ( "Bad field type %T" , field ) )
panic ( fmt . Sprintf ( "Bad field type %T" , field . Interface ( ) ) )
}
}
// func isLt(top interface{}, current interface{}, field interface{}, param string) bool {
// func isLt(top interface{}, current interface{}, field interface{}, param string) bool {