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
1 changed files with 11 additions and 2 deletions

View File

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