diff --git a/forms.go b/forms.go index 5280e41..664cab2 100644 --- a/forms.go +++ b/forms.go @@ -1,6 +1,7 @@ package forms import ( + "encoding" "reflect" "strconv" "strings" @@ -26,13 +27,21 @@ func decode(form Values, rv reflect.Value, prefix string) { continue } - // TODO: Add custom interface - fe := ft.Type if fe.Kind() == reflect.Ptr { fe = fe.Elem() } + if tu, ok := fv.Addr().Interface().(encoding.TextUnmarshaler); ok { + v, ok := form[getName(ft, prefix)] + if !ok || len(v) == 0 { + continue + } + + tu.UnmarshalText([]byte(v[0])) + continue + } + if fe.Kind() == reflect.Struct { if fv.Kind() == reflect.Ptr { found := false