Skip to content

Commit 4a08853

Browse files
committed
处理默认值
1 parent 5b4703a commit 4a08853

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

binder.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package echox
22

33
import (
4-
"github.com/labstack/echo/v4"
5-
"github.com/mcuadros/go-defaults"
4+
`reflect`
5+
6+
`github.com/labstack/echo/v4`
7+
`github.com/mcuadros/go-defaults`
68
)
79

810
type binder struct{}
@@ -14,7 +16,12 @@ func (b *binder) Bind(data interface{}, ctx echo.Context) (err error) {
1416
}
1517

1618
// 处理默认值
17-
defaults.SetDefaults(data)
19+
// 区分指针类型和非指针类型
20+
if reflect.ValueOf(data).Kind() == reflect.Ptr {
21+
defaults.SetDefaults(data)
22+
} else {
23+
defaults.SetDefaults(&data)
24+
}
1825

1926
return
2027
}

0 commit comments

Comments
 (0)