From 9654077b1b05cbad899fd85f05f7125eb292e431 Mon Sep 17 00:00:00 2001 From: cloud Date: Tue, 2 Jun 2026 22:47:48 +0800 Subject: [PATCH 1/4] delete one row --- binding/form_mapping.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index 6982fd4f..c42fa997 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -146,8 +146,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter var tagValue string var setOpt setOptions - tagValue = field.Tag.Get(tag) - tagValue, opts := head(tagValue, ",") + tagValue, opts := head(field.Tag.Get(tag), ",") if tagValue == "" { // default value is FieldName tagValue = field.Name From 14f0702ccf2d6e7388a8ff13caad0b26c844151b Mon Sep 17 00:00:00 2001 From: cloud Date: Wed, 3 Jun 2026 13:08:25 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1=EF=BC=9AtagValue=20only=20needs=20to=20be?= =?UTF-8?q?=20assigned=20once,=20which=20removes=20an=20unnecessary=20step?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2:This reduces a redundant check. When tagValue is empty, we can first check whether field.Name is empty before assigning it. 3: With this approach, the comment in the second block can also be removed. The second invocation of k, v := head(opt, "=") in the original code appears to be unnecessary and can be removed. Some of these changes may be too minor to provide any meaningful benefit, and the actual optimization is very limited. Please feel free to ignore any suggestions that do not seem worthwhile. --- binding/form_mapping.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index c42fa997..836bef00 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -143,23 +143,22 @@ type setOptions struct { } func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) { - var tagValue string var setOpt setOptions tagValue, opts := head(field.Tag.Get(tag), ",") if tagValue == "" { // default value is FieldName + if field.Name == "" { + return false, nil + } tagValue = field.Name } - if tagValue == "" { // when field is "emptyField" variable - return false, nil - } var opt string for len(opts) > 0 { opt, opts = head(opts, ",") - - if k, v := head(opt, "="); k == "default" { + k, v := head(opt, "=") + if k == "default" { setOpt.isDefaultExists = true setOpt.defaultValue = v @@ -170,7 +169,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter setOpt.defaultValue = strings.ReplaceAll(v, ";", ",") } } - } else if k, v = head(opt, "="); k == "parser" { + } else if k == "parser" { setOpt.parser = v } } From 95fc7031a7f0efab17cf7933a896cc205d201b8c Mon Sep 17 00:00:00 2001 From: cloud Date: Wed, 3 Jun 2026 13:08:25 +0800 Subject: [PATCH 3/4] =?UTF-8?q?1=EF=BC=9AtagValue=20only=20needs=20to=20be?= =?UTF-8?q?=20assigned=20once,=20which=20removes=20an=20unnecessary=20step?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2:This reduces a redundant check. When tagValue is empty, we can first check whether field.Name is empty before assigning it.With this approach, the comment in the second block can also be removed. 3:The second invocation of k, v := head(opt, "=") in the original code appears to be unnecessary and can be removed. Some of these changes may be too minor to provide any meaningful benefit, and the actual optimization is very limited. Please feel free to ignore any suggestions that do not seem worthwhile. --- binding/form_mapping.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index c42fa997..836bef00 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -143,23 +143,22 @@ type setOptions struct { } func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) { - var tagValue string var setOpt setOptions tagValue, opts := head(field.Tag.Get(tag), ",") if tagValue == "" { // default value is FieldName + if field.Name == "" { + return false, nil + } tagValue = field.Name } - if tagValue == "" { // when field is "emptyField" variable - return false, nil - } var opt string for len(opts) > 0 { opt, opts = head(opts, ",") - - if k, v := head(opt, "="); k == "default" { + k, v := head(opt, "=") + if k == "default" { setOpt.isDefaultExists = true setOpt.defaultValue = v @@ -170,7 +169,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter setOpt.defaultValue = strings.ReplaceAll(v, ";", ",") } } - } else if k, v = head(opt, "="); k == "parser" { + } else if k == "parser" { setOpt.parser = v } } From 372204cb839e2bf26b5019f71579bb929d2c58bd Mon Sep 17 00:00:00 2001 From: cloud Date: Wed, 3 Jun 2026 13:25:45 +0800 Subject: [PATCH 4/4] change if/else if to switch --- binding/form_mapping.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/binding/form_mapping.go b/binding/form_mapping.go index 836bef00..6213641e 100644 --- a/binding/form_mapping.go +++ b/binding/form_mapping.go @@ -158,7 +158,8 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter for len(opts) > 0 { opt, opts = head(opts, ",") k, v := head(opt, "=") - if k == "default" { + switch k { + case "default": setOpt.isDefaultExists = true setOpt.defaultValue = v @@ -169,7 +170,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter setOpt.defaultValue = strings.ReplaceAll(v, ";", ",") } } - } else if k == "parser" { + case "parser": setOpt.parser = v } }