Update simple.go file && README

pull/137/head
joeybloggs 9 years ago
parent d363ed316c
commit 6a8ed5612a
  1. 15
      README.md
  2. 15
      examples/simple.go

@ -170,6 +170,21 @@ func (v valuer) Value() (sql.Value, error) {
return v.Name, nil return v.Name, nil
} }
// ValidateValuerType implements validator.CustomTypeFunc
func ValidateValuerType(field reflect.Value) interface{} {
if valuer, ok := field.Interface().(sql.Valuer); ok {
val, err := valuer.Value()
if err != nil {
// handle the error how you want
return nil
}
return val
}
return nil
}
func main() { func main() {
customTypes := map[reflect.Type]validator.CustomTypeFunc{} customTypes := map[reflect.Type]validator.CustomTypeFunc{}

@ -118,6 +118,21 @@ func (v valuer) Value() (sql.Value, error) {
return v.Name, nil return v.Name, nil
} }
// ValidateValuerType implements validator.CustomTypeFunc
func ValidateValuerType(field reflect.Value) interface{} {
if valuer, ok := field.Interface().(sql.Valuer); ok {
val, err := valuer.Value()
if err != nil {
// handle the error how you want
return nil
}
return val
}
return nil
}
func main2() { func main2() {
customTypes := map[reflect.Type]validator.CustomTypeFunc{} customTypes := map[reflect.Type]validator.CustomTypeFunc{}

Loading…
Cancel
Save