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
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user