You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
when i call /b/c, i want to just call the BDone method finnaly, but it called both ADone and BDone method. After searching in the source code i found there are two methods strange:
// Party groups routes which may have the same prefix and share same handlers,
// returns that new rich subrouter.
//
// You can even declare a subdomain with relativePath as "mysub." or see `Subdomain`.
func (api *APIBuilder) Party(relativePath string, handlers ...context.Handler) Party {
parentPath := api.relativePath
dot := string(SubdomainPrefix[0])
if len(parentPath) > 0 && parentPath[0] == '/' && strings.HasSuffix(relativePath, dot) {
// if ends with . , i.e admin., it's subdomain->
parentPath = parentPath[1:] // remove first slash
}
// this is checked later on but for easier debug is better to do it here:
if api.relativePath[len(api.relativePath)-1] == '/' && relativePath[0] == '/' {
relativePath = relativePath[1:] // remove first slash if parent ended with / and new one started with /.
}
// if it's subdomain then it has priority, i.e:
// api.relativePath == "admin."
// relativePath == "panel."
// then it should be panel.admin.
// instead of admin.panel.
if hasSubdomain(parentPath) && hasSubdomain(relativePath) {
relativePath = relativePath + parentPath
parentPath = ""
}
fullpath := parentPath + relativePath
// append the parent's + child's handlers
middleware := joinHandlers(api.middleware, handlers)
return &APIBuilder{
// global/api builder
macros: api.macros,
routes: api.routes,
errorCodeHandlers: api.errorCodeHandlers,
beginGlobalHandlers: api.beginGlobalHandlers,
doneGlobalHandlers: api.doneGlobalHandlers,
reporter: api.reporter,
// per-party/children
middleware: middleware,
relativePath: fullpath,
}
}
// Done appends to the very end, Handler(s) to the current Party's routes and child routes
// The difference from .Use is that this/or these Handler(s) are being always running last.
func (api *APIBuilder) Done(handlers ...context.Handler) {
for _, r := range api.routes.routes {
r.done(handlers) // append the handlers to the existing routes
}
// set as done handlers for the next routes as well.
api.doneGlobalHandlers = append(api.doneGlobalHandlers, handlers...)
}
The Party method set the global routes api.routes to the APIBuilder, and then return it, the Done method range the api.routes.routes to append the handlers to the existing routes, lead to the above result.
Why the Done method use the api.routes.routes? When use api.routes.routes, the actual execute result will rely on the order that the routes registed and it may lead to unexpected result when work together. I think it should use api.apiRoutes instead of api.routes.routes.
The text was updated successfully, but these errors were encountered:
You've almost right, the apiRoutes are not used, we don't need them because we have different variables for begin handlers and done handlers and they are managed at the Handle method, the apiRoutes are there but are not used anywhere, they will be removed. You have right, that the Done registers done handlers to all routes instead of its party's only, that's the problem but that was not by accident, that was my itention, it was created before the UseGlobal, so now I will fix the Done and add the DoneGlobal as well. I will deal with it right now, let me prepare a coffee first :)
I am new to use iris. I am not sure what i said is right, but just feel the party's done method is strange.
For example:
when i call /b/c, i want to just call the BDone method finnaly, but it called both ADone and BDone method. After searching in the source code i found there are two methods strange:
The Party method set the global routes api.routes to the APIBuilder, and then return it, the Done method range the api.routes.routes to append the handlers to the existing routes, lead to the above result.
Why the Done method use the api.routes.routes? When use api.routes.routes, the actual execute result will rely on the order that the routes registed and it may lead to unexpected result when work together. I think it should use api.apiRoutes instead of api.routes.routes.
The text was updated successfully, but these errors were encountered: