From 6a8ed5612a7653aabbc09c69b301c4f9ee3145d5 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Thu, 30 Jul 2015 22:44:06 -0400 Subject: [PATCH] Update simple.go file && README --- README.md | 15 +++++++++++++++ examples/simple.go | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/README.md b/README.md index 6c88537..32fc641 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,21 @@ func (v valuer) Value() (sql.Value, error) { 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() { customTypes := map[reflect.Type]validator.CustomTypeFunc{} diff --git a/examples/simple.go b/examples/simple.go index fd503c4..b685dda 100644 --- a/examples/simple.go +++ b/examples/simple.go @@ -118,6 +118,21 @@ func (v valuer) Value() (sql.Value, error) { 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() { customTypes := map[reflect.Type]validator.CustomTypeFunc{}