mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 13:05:56 +00:00
dependency injection: fix read slices
rel: https://github.com/kataras/iris/issues/1542 Former-commit-id: 0028fafa60b80c80cade1e7a18a11109ce0e9948
This commit is contained in:
@@ -209,7 +209,7 @@ func getBindingsFor(inputs []reflect.Type, deps []*Dependency, paramsCount int)
|
||||
}
|
||||
|
||||
// else add builtin bindings that may be registered by user too, but they didn't.
|
||||
if indirectType(in).Kind() == reflect.Struct {
|
||||
if isPayloadType(in) {
|
||||
bindings = append(bindings, payloadBinding(i, in))
|
||||
continue
|
||||
}
|
||||
@@ -219,6 +219,15 @@ func getBindingsFor(inputs []reflect.Type, deps []*Dependency, paramsCount int)
|
||||
return
|
||||
}
|
||||
|
||||
func isPayloadType(in reflect.Type) bool {
|
||||
switch indirectType(in).Kind() {
|
||||
case reflect.Struct, reflect.Slice:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func getBindingsForFunc(fn reflect.Value, dependencies []*Dependency, paramsCount int) []*binding {
|
||||
fnTyp := fn.Type()
|
||||
if !isFunc(fnTyp) {
|
||||
@@ -331,9 +340,15 @@ func payloadBinding(index int, typ reflect.Type) *binding {
|
||||
}
|
||||
}
|
||||
|
||||
newValue = reflect.New(indirectType(input.Type))
|
||||
if input.Type.Kind() == reflect.Slice {
|
||||
newValue = reflect.New(reflect.SliceOf(indirectType(input.Type)))
|
||||
} else {
|
||||
newValue = reflect.New(indirectType(input.Type))
|
||||
}
|
||||
|
||||
ptr := newValue.Interface()
|
||||
err = ctx.ReadBody(ptr)
|
||||
|
||||
if !wasPtr {
|
||||
newValue = newValue.Elem()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user