Skip to content

Commit 6a8ed56

Browse files
joeybloggsjoeybloggs
authored andcommitted
Update simple.go file && README
1 parent d363ed3 commit 6a8ed56

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,21 @@ func (v valuer) Value() (sql.Value, error) {
170170
return v.Name, nil
171171
}
172172

173+
// ValidateValuerType implements validator.CustomTypeFunc
174+
func ValidateValuerType(field reflect.Value) interface{} {
175+
if valuer, ok := field.Interface().(sql.Valuer); ok {
176+
val, err := valuer.Value()
177+
if err != nil {
178+
// handle the error how you want
179+
return nil
180+
}
181+
182+
return val
183+
}
184+
185+
return nil
186+
}
187+
173188
func main() {
174189

175190
customTypes := map[reflect.Type]validator.CustomTypeFunc{}

examples/simple.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,21 @@ func (v valuer) Value() (sql.Value, error) {
118118
return v.Name, nil
119119
}
120120

121+
// ValidateValuerType implements validator.CustomTypeFunc
122+
func ValidateValuerType(field reflect.Value) interface{} {
123+
if valuer, ok := field.Interface().(sql.Valuer); ok {
124+
val, err := valuer.Value()
125+
if err != nil {
126+
// handle the error how you want
127+
return nil
128+
}
129+
130+
return val
131+
}
132+
133+
return nil
134+
}
135+
121136
func main2() {
122137

123138
customTypes := map[reflect.Type]validator.CustomTypeFunc{}

0 commit comments

Comments
 (0)