mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-24 02:32:17 +08:00
use SplitN and optimization code
This commit is contained in:
parent
b4d1b55cc2
commit
4654192b83
@ -26,10 +26,10 @@ func mapForm(ptr interface{}, form map[string][]string) error {
|
|||||||
inputFieldName := typeField.Tag.Get("form")
|
inputFieldName := typeField.Tag.Get("form")
|
||||||
inputFieldNameList := strings.Split(inputFieldName, ",")
|
inputFieldNameList := strings.Split(inputFieldName, ",")
|
||||||
inputFieldName = inputFieldNameList[0]
|
inputFieldName = inputFieldNameList[0]
|
||||||
var defaultValue interface{}
|
var defaultValue string
|
||||||
if len(inputFieldNameList) > 1 {
|
if len(inputFieldNameList) > 1 {
|
||||||
defaultList := strings.Split(inputFieldNameList[1], "=")
|
defaultList := strings.SplitN(inputFieldNameList[1], "=", 2)
|
||||||
if len(defaultList) == 2 && defaultList[0] == "default" {
|
if defaultList[0] == "default" {
|
||||||
defaultValue = defaultList[1]
|
defaultValue = defaultList[1]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -50,11 +50,11 @@ func mapForm(ptr interface{}, form map[string][]string) error {
|
|||||||
inputValue, exists := form[inputFieldName]
|
inputValue, exists := form[inputFieldName]
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
if defaultValue == nil {
|
if defaultValue == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
inputValue = make([]string, 1)
|
inputValue = make([]string, 1)
|
||||||
inputValue[0] = defaultValue.(string)
|
inputValue[0] = defaultValue
|
||||||
}
|
}
|
||||||
|
|
||||||
numElems := len(inputValue)
|
numElems := len(inputValue)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user