1
0
mirror of https://github.com/labstack/echo.git synced 2025-03-23 21:29:26 +02:00

Add pointer binding of proper types to DefaultBinder (#915)

This commit is contained in:
Christopher Probst 2017-04-28 20:07:20 +02:00 committed by Vishal Rana
parent 0dfcb31d9e
commit f3f3e99ba3
2 changed files with 30 additions and 1 deletions

View File

@ -142,6 +142,8 @@ func setWithProperType(valueKind reflect.Kind, val string, structField reflect.V
} }
switch valueKind { switch valueKind {
case reflect.Ptr:
return setWithProperType(structField.Elem().Kind(), val, structField.Elem())
case reflect.Int: case reflect.Int:
return setIntField(val, 0, structField) return setIntField(val, 0, structField)
case reflect.Int8: case reflect.Int8:

View File

@ -17,26 +17,39 @@ import (
type ( type (
bindTestStruct struct { bindTestStruct struct {
I int I int
PtrI *int
I8 int8 I8 int8
PtrI8 *int8
I16 int16 I16 int16
PtrI16 *int16
I32 int32 I32 int32
PtrI32 *int32
I64 int64 I64 int64
PtrI64 *int64
UI uint UI uint
PtrUI *uint
UI8 uint8 UI8 uint8
PtrUI8 *uint8
UI16 uint16 UI16 uint16
PtrUI16 *uint16
UI32 uint32 UI32 uint32
PtrUI32 *uint32
UI64 uint64 UI64 uint64
PtrUI64 *uint64
B bool B bool
PtrB *bool
F32 float32 F32 float32
PtrF32 *float32
F64 float64 F64 float64
PtrF64 *float64
S string S string
PtrS *string
cantSet string cantSet string
DoesntExist string DoesntExist string
T Timestamp T Timestamp
Tptr *Timestamp Tptr *Timestamp
SA StringArray SA StringArray
} }
Timestamp time.Time Timestamp time.Time
TA []Timestamp TA []Timestamp
StringArray []string StringArray []string
@ -69,19 +82,33 @@ func (t bindTestStruct) GetCantSet() string {
var values = map[string][]string{ var values = map[string][]string{
"I": {"0"}, "I": {"0"},
"PtrI": {"0"},
"I8": {"8"}, "I8": {"8"},
"PtrI8": {"8"},
"I16": {"16"}, "I16": {"16"},
"PtrI16": {"16"},
"I32": {"32"}, "I32": {"32"},
"PtrI32": {"32"},
"I64": {"64"}, "I64": {"64"},
"PtrI64": {"64"},
"UI": {"0"}, "UI": {"0"},
"PtrUI": {"0"},
"UI8": {"8"}, "UI8": {"8"},
"PtrUI8": {"8"},
"UI16": {"16"}, "UI16": {"16"},
"PtrUI16": {"16"},
"UI32": {"32"}, "UI32": {"32"},
"PtrUI32": {"32"},
"UI64": {"64"}, "UI64": {"64"},
"PtrUI64": {"64"},
"B": {"true"}, "B": {"true"},
"PtrB": {"true"},
"F32": {"32.5"}, "F32": {"32.5"},
"PtrF32": {"32.5"},
"F64": {"64.5"}, "F64": {"64.5"},
"PtrF64": {"64.5"},
"S": {"test"}, "S": {"test"},
"PtrS": {"test"},
"cantSet": {"test"}, "cantSet": {"test"},
"T": {"2016-12-06T19:09:05+01:00"}, "T": {"2016-12-06T19:09:05+01:00"},
"Tptr": {"2016-12-06T19:09:05+01:00"}, "Tptr": {"2016-12-06T19:09:05+01:00"},