mirror of
https://github.com/kataras/iris.git
synced 2025-12-21 03:47:04 +00:00
make the macro#Parse to return a value of a Template instead of its ptr and debug logs for handlers length ignores the internal generated macro evaluator handler if it is there, so end-dev cannot be confused about the debug logs at that point
Former-commit-id: c23a3d10b43f145de575f1ea11e3dbf9bbd33a6b
This commit is contained in:
@@ -13,11 +13,11 @@ import (
|
||||
// If any of the following fields are changed then the
|
||||
// caller should Refresh the router.
|
||||
type Route struct {
|
||||
Name string `json:"name"` // "userRoute"
|
||||
Method string `json:"method"` // "GET"
|
||||
methodBckp string // if Method changed to something else (which is possible at runtime as well, via RefreshRouter) then this field will be filled with the old one.
|
||||
Subdomain string `json:"subdomain"` // "admin."
|
||||
tmpl *macro.Template // Tmpl().Src: "/api/user/{id:uint64}"
|
||||
Name string `json:"name"` // "userRoute"
|
||||
Method string `json:"method"` // "GET"
|
||||
methodBckp string // if Method changed to something else (which is possible at runtime as well, via RefreshRouter) then this field will be filled with the old one.
|
||||
Subdomain string `json:"subdomain"` // "admin."
|
||||
tmpl macro.Template // Tmpl().Src: "/api/user/{id:uint64}"
|
||||
// temp storage, they're appended to the Handlers on build.
|
||||
// Execution happens before Handlers, can be empty.
|
||||
beginHandlers context.Handlers
|
||||
@@ -50,7 +50,8 @@ func NewRoute(method, subdomain, unparsedPath, mainHandlerName string,
|
||||
path := convertMacroTmplToNodePath(tmpl)
|
||||
// prepend the macro handler to the route, now,
|
||||
// right before the register to the tree, so APIBuilder#UseGlobal will work as expected.
|
||||
if macroEvaluatorHandler, ok := handler.MakeHandler(tmpl); ok {
|
||||
if handler.CanMakeHandler(tmpl) {
|
||||
macroEvaluatorHandler := handler.MakeHandler(tmpl)
|
||||
handlers = append(context.Handlers{macroEvaluatorHandler}, handlers...)
|
||||
}
|
||||
|
||||
@@ -155,7 +156,18 @@ func (r Route) String() string {
|
||||
// via Tmpl().Src, Route.Path is the path
|
||||
// converted to match the underline router's specs.
|
||||
func (r Route) Tmpl() macro.Template {
|
||||
return *r.tmpl
|
||||
return r.tmpl
|
||||
}
|
||||
|
||||
// RegisteredHandlersLen returns the end-developer's registered handlers, all except the macro evaluator handler
|
||||
// if was required by the build process.
|
||||
func (r Route) RegisteredHandlersLen() int {
|
||||
n := len(r.Handlers)
|
||||
if handler.CanMakeHandler(r.tmpl) {
|
||||
n--
|
||||
}
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// IsOnline returns true if the route is marked as "online" (state).
|
||||
@@ -245,7 +257,8 @@ func (r Route) Trace() string {
|
||||
printfmt += fmt.Sprintf(" %s", r.Subdomain)
|
||||
}
|
||||
printfmt += fmt.Sprintf(" %s ", r.Tmpl().Src)
|
||||
if l := len(r.Handlers); l > 1 {
|
||||
|
||||
if l := r.RegisteredHandlersLen(); l > 1 {
|
||||
printfmt += fmt.Sprintf("-> %s() and %d more", r.MainHandlerName, l-1)
|
||||
} else {
|
||||
printfmt += fmt.Sprintf("-> %s()", r.MainHandlerName)
|
||||
|
||||
Reference in New Issue
Block a user