1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-27 05:45:56 +00:00

Add session.Destroy (before I've added: Increment & Decrement entry helpers as well) | Improve the debug messages for the controllers

Former-commit-id: f5f17b05252a5032ace1e2d0fdd2304fc4004635
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-12-16 23:09:00 +02:00
parent b8cafce6b9
commit 68cc6641d4
7 changed files with 119 additions and 53 deletions

View File

@@ -1,6 +1,9 @@
package di
import "reflect"
import (
"fmt"
"reflect"
)
type (
targetFuncInput struct {
@@ -18,7 +21,9 @@ type (
Length int
// Valid is True when `Length` is > 0, it's statically set-ed for
// performance reasons.
Valid bool //
Valid bool
trace string // for debug info.
}
)
@@ -83,9 +88,29 @@ func MakeFuncInjector(fn reflect.Value, hijack Hijacker, goodFunc TypeChecker, v
// s.Length = n
s.Length = len(s.inputs)
s.Valid = s.Length > 0
for i, in := range s.inputs {
bindmethodTyp := "Static"
if in.Object.BindType == Dynamic {
bindmethodTyp = "Dynamic"
}
typIn := typ.In(in.InputIndex)
// remember: on methods that are part of a struct (i.e controller)
// the input index = 1 is the begggining instead of the 0,
// because the 0 is the controller receiver pointer of the method.
s.trace += fmt.Sprintf("[%d] %s binding: '%s' for input position: %d and type: '%s'\n", i+1, bindmethodTyp, in.Object.Type.String(), in.InputIndex, typIn.String())
}
return s
}
func (s *FuncInjector) String() string {
return s.trace
}
func (s *FuncInjector) Inject(in *[]reflect.Value, ctx ...reflect.Value) {
args := *in
for _, input := range s.inputs {

View File

@@ -1,6 +1,9 @@
package di
import "reflect"
import (
"fmt"
"reflect"
)
type (
targetStructField struct {
@@ -13,6 +16,8 @@ type (
//
fields []*targetStructField
Valid bool // is True when contains fields and it's a valid target struct.
trace string // for debug info.
}
)
@@ -56,9 +61,25 @@ func MakeStructInjector(v reflect.Value, hijack Hijacker, goodFunc TypeChecker,
}
s.Valid = len(s.fields) > 0
if s.Valid {
for i, f := range s.fields {
bindmethodTyp := "Static"
if f.Object.BindType == Dynamic {
bindmethodTyp = "Dynamic"
}
elemField := s.elemType.FieldByIndex(f.FieldIndex)
s.trace += fmt.Sprintf("[%d] %s binding: '%s' for field '%s %s'\n", i+1, bindmethodTyp, f.Object.Type.String(), elemField.Name, elemField.Type.String())
}
}
return s
}
func (s *StructInjector) String() string {
return s.trace
}
func (s *StructInjector) Inject(dest interface{}, ctx ...reflect.Value) {
if dest == nil {
return