mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-18 06:42:10 +08:00
mutliple -> multiple
This commit is contained in:
parent
2f293b7df9
commit
2e7b3851a5
@ -937,7 +937,7 @@ import (
|
|||||||
type Workplace struct {
|
type Workplace struct {
|
||||||
Employee string `form:"employee"`
|
Employee string `form:"employee"`
|
||||||
Location string `form:"address,default=headquarter"`
|
Location string `form:"address,default=headquarter"`
|
||||||
Peripherals []string `form:"peripherals,mutliple_default,default=monitor,mouse,keyboard`
|
Peripherals []string `form:"peripherals,multiple_default,default=monitor,mouse,keyboard`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -953,7 +953,7 @@ func startPage(c *gin.Context) {
|
|||||||
// If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`).
|
// If `POST`, first checks the `content-type` for `JSON` or `XML`, then uses `Form` (`form-data`).
|
||||||
// See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48
|
// See more at https://github.com/gin-gonic/gin/blob/master/binding/binding.go#L48
|
||||||
// If default value defined, and the Request does not contain the key, the default value will be used. Empty value from request overrides that behaviour
|
// If default value defined, and the Request does not contain the key, the default value will be used. Empty value from request overrides that behaviour
|
||||||
// If mutliple_default is in front of default, the 'default' value is returned as a slice, the position of mutliple_default is important
|
// If multiple_default is in front of default, the 'default' value is returned as a slice, the position of multiple_default is important
|
||||||
if c.ShouldBind(&workplace) == nil {
|
if c.ShouldBind(&workplace) == nil {
|
||||||
log.Println(workplace.Employee)
|
log.Println(workplace.Employee)
|
||||||
log.Println(workplace.Location)
|
log.Println(workplace.Location)
|
||||||
|
@ -142,7 +142,7 @@ func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter
|
|||||||
var opt string
|
var opt string
|
||||||
for len(opts) > 0 {
|
for len(opts) > 0 {
|
||||||
opt, opts = head(opts, ",")
|
opt, opts = head(opts, ",")
|
||||||
if k, _ := head(opt, "="); k == "mutliple_default" {
|
if k, _ := head(opt, "="); k == "multiple_default" {
|
||||||
_, values := head(opts, "=")
|
_, values := head(opts, "=")
|
||||||
setOpt.isDefaultExists = true
|
setOpt.isDefaultExists = true
|
||||||
setOpt.defaultValue = values
|
setOpt.defaultValue = values
|
||||||
|
@ -76,9 +76,9 @@ func TestMappingDefault(t *testing.T) {
|
|||||||
|
|
||||||
func TestMappingMultipleDefault(t *testing.T) {
|
func TestMappingMultipleDefault(t *testing.T) {
|
||||||
var s struct {
|
var s struct {
|
||||||
Int int `form:",mutliple_default,default=9"`
|
Int int `form:",multiple_default,default=9"`
|
||||||
Slice []int `form:",mutliple_default,default=9"`
|
Slice []int `form:",multiple_default,default=9"`
|
||||||
Array [1]int `form:",mutliple_default,default=9"`
|
Array [1]int `form:",multiple_default,default=9"`
|
||||||
}
|
}
|
||||||
err := mappingByPtr(&s, formSource{}, "form")
|
err := mappingByPtr(&s, formSource{}, "form")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user