mirror of
https://github.com/kataras/iris.git
synced 2026-03-06 00:16:12 +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:
@@ -2,6 +2,7 @@ package mvc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/kataras/golog"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@@ -220,9 +221,17 @@ func (c *ControllerActivator) Handle(method, path, funcName string, middleware .
|
||||
// this is a logical flow, so we will choose that one ->
|
||||
if c.injector == nil {
|
||||
c.injector = c.Dependencies.Struct(c.Value)
|
||||
if c.injector.Valid {
|
||||
golog.Debugf("MVC dependencies of '%s':\n%s", c.FullName, c.injector.String())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
handler := buildHandler(m, c.Type, c.Value, c.injector, funcInjector, funcIn)
|
||||
if funcInjector.Valid {
|
||||
golog.Debugf("MVC dependencies of method '%s.%s':\n%s", c.FullName, funcName, funcInjector.String())
|
||||
}
|
||||
|
||||
handler := buildControllerHandler(m, c.Type, c.Value, c.injector, funcInjector, funcIn)
|
||||
|
||||
// register the handler now.
|
||||
route := c.Router.Handle(method, path, append(middleware, handler)...)
|
||||
@@ -235,10 +244,10 @@ func (c *ControllerActivator) Handle(method, path, funcName string, middleware .
|
||||
return route
|
||||
}
|
||||
|
||||
// buildHandler has many many dublications but we do that to achieve the best
|
||||
// buildControllerHandler has many many dublications but we do that to achieve the best
|
||||
// performance possible, to use the information we know
|
||||
// and calculate what is needed and what not in serve-time.
|
||||
func buildHandler(m reflect.Method, typ reflect.Type, initRef reflect.Value, structInjector *di.StructInjector, funcInjector *di.FuncInjector, funcIn []reflect.Type) context.Handler {
|
||||
func buildControllerHandler(m reflect.Method, typ reflect.Type, initRef reflect.Value, structInjector *di.StructInjector, funcInjector *di.FuncInjector, funcIn []reflect.Type) context.Handler {
|
||||
var (
|
||||
hasStructInjector = structInjector != nil && structInjector.Valid
|
||||
hasFuncInjector = funcInjector != nil && funcInjector.Valid
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user