Add support for custom validation rules
This commit is contained in:
parent
922297b368
commit
f79b7c6649
4 changed files with 54 additions and 20 deletions
14
input.go
14
input.go
|
@ -6,15 +6,21 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
func inputInt(kind reflect.Kind, value string) interface{} {
|
||||
return int(inputSame(reflect.Int, value).(int64))
|
||||
// InputFunc is a function that converts the parameter of a validation rule to the desired type
|
||||
type InputFunc func(reflect.Kind, string) interface{}
|
||||
|
||||
// InputInt always returns an int
|
||||
func InputInt(kind reflect.Kind, value string) interface{} {
|
||||
return int(InputSame(reflect.Int, value).(int64))
|
||||
}
|
||||
|
||||
func inputRegexp(kind reflect.Kind, value string) interface{} {
|
||||
// InputRegexp always returns a compiled regular expression
|
||||
func InputRegexp(kind reflect.Kind, value string) interface{} {
|
||||
return regexp.MustCompile(value)
|
||||
}
|
||||
|
||||
func inputSame(kind reflect.Kind, value string) interface{} {
|
||||
// InputSame returns the type matching the field
|
||||
func InputSame(kind reflect.Kind, value string) interface{} {
|
||||
var val interface{}
|
||||
var err error
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue