forked from Fuyu/forms
Add support for TextUnmarshaler
This commit is contained in:
parent
86d83285ed
commit
122175c75b
13
forms.go
13
forms.go
@ -1,6 +1,7 @@
|
|||||||
package forms
|
package forms
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -26,13 +27,21 @@ func decode(form Values, rv reflect.Value, prefix string) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add custom interface
|
|
||||||
|
|
||||||
fe := ft.Type
|
fe := ft.Type
|
||||||
if fe.Kind() == reflect.Ptr {
|
if fe.Kind() == reflect.Ptr {
|
||||||
fe = fe.Elem()
|
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 fe.Kind() == reflect.Struct {
|
||||||
if fv.Kind() == reflect.Ptr {
|
if fv.Kind() == reflect.Ptr {
|
||||||
found := false
|
found := false
|
||||||
|
Loading…
Reference in New Issue
Block a user