1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-23 12:57:05 +00:00

next version preparation: hero: add a Container.Inject method to inject values outside of HTTP lifecycle, e.g. a database may be used by other services outside of Iris, the hero container (and API's Builder.GetContainer()) should provide it.

Former-commit-id: 89863055a3a3ab108a3f4b753072a35321a3a193
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-03-05 19:49:45 +02:00
parent 5ee06f9a92
commit b6445c7238
4 changed files with 133 additions and 14 deletions

View File

@@ -7,14 +7,23 @@ import (
)
func valueOf(v interface{}) reflect.Value {
if v, ok := v.(reflect.Value); ok {
if val, ok := v.(reflect.Value); ok {
// check if it's already a reflect.Value.
return v
return val
}
return reflect.ValueOf(v)
}
func typeOf(typ interface{}) reflect.Type {
if v, ok := typ.(reflect.Type); ok {
// check if it's already a reflect.Type.
return v
}
return reflect.TypeOf(typ)
}
// indirectType returns the value of a pointer-type "typ".
// If "typ" is a pointer, array, chan, map or slice it returns its Elem,
// otherwise returns the typ as it's.
@@ -82,9 +91,8 @@ func equalTypes(binding reflect.Type, input reflect.Type) bool {
// if accepts an interface, check if the given "got" type does
// implement this "expected" user handler's input argument.
if input.Kind() == reflect.Interface {
// fmt.Printf("expected interface = %s and got to set on the arg is: %s\n", expected.String(), got.String())
// return got.Implements(expected)
// return expected.AssignableTo(got)
// fmt.Printf("expected interface = %s and got to set on the arg is: %s\n", binding.String(), input.String())
// return input.Implements(binding)
return binding.AssignableTo(input)
}