From 3bd7614ade4f0b9d5cd9d7f2da972a4c370805b8 Mon Sep 17 00:00:00 2001 From: Witaya Tospitakkul Date: Fri, 25 Jan 2019 11:00:24 +0700 Subject: [PATCH] refactoring code after discussion --- templatefunc.go | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/templatefunc.go b/templatefunc.go index eeb34cc6..d302cb64 100644 --- a/templatefunc.go +++ b/templatefunc.go @@ -297,24 +297,18 @@ func parseFormToStruct(form url.Values, objT reflect.Type, objV reflect.Value) e tag = tags[0] } - if fieldT.Type.Kind() == reflect.Slice { - found := false - for _, v := range form[tag] { - if len(v) != 0 { - found = true - break - } - } - if !found { + formValues := form[tag] + var value string + if len(formValues) == 0 { + continue + } + if len(formValues) == 1 { + value = formValues[0] + if value == "" { continue } } - value := form.Get(tag) - if (fieldT.Type.Kind() != reflect.Slice) && len(value) == 0 { - continue - } - switch fieldT.Type.Kind() { case reflect.Bool: if strings.ToLower(value) == "on" || strings.ToLower(value) == "1" || strings.ToLower(value) == "yes" {