Add support for TextUnmarshaler

This commit is contained in:
Nise Void 2019-07-18 15:14:04 +02:00
parent 86d83285ed
commit 122175c75b
Signed by: NiseVoid
GPG Key ID: FBA14AC83EA602F3

View File

@ -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