MCPcopy Create free account
hub / github.com/kataras/iris / createRoutes

Method createRoutes

core/router/api_builder.go:706–816  ·  view source on GitHub ↗
(errorCode int, methods []string, relativePath string, handlers ...context.Handler)

Source from the content-addressed store, hash-verified

704}
705
706func (api *APIBuilder) createRoutes(errorCode int, methods []string, relativePath string, handlers ...context.Handler) []*Route {
707 if statusCodeSuccessful(errorCode) {
708 errorCode = 0
709 }
710
711 mainHandlers := context.CopyHandlers(handlers)
712
713 if errorCode == 0 {
714 if len(methods) == 0 || methods[0] == "ALL" || methods[0] == "ANY" { // then use like it was .Any
715 return api.Any(relativePath, mainHandlers...)
716 }
717 }
718
719 // no clean path yet because of subdomain indicator/separator which contains a dot.
720 // but remove the first slash if the relative has already ending with a slash
721 // it's not needed because later on we do normalize/clean the path, but better do it here too
722 // for any future updates.
723 if api.relativePath[len(api.relativePath)-1] == '/' {
724 if relativePath[0] == '/' {
725 relativePath = relativePath[1:]
726 }
727 }
728
729 filename, line := hero.GetCaller()
730
731 fullpath := api.relativePath + relativePath // for now, keep the last "/" if any, "/xyz/"
732 if len(mainHandlers) == 0 {
733 api.logger.Errorf("missing handlers for route[%s:%d] %s: %s", filename, line, strings.Join(methods, ", "), fullpath)
734 return nil
735 }
736
737 // note: this can not change the caller's handlers as they're but the entry values(handlers)
738 // of `middleware`, `doneHandlers` and `handlers` can.
739 // So if we just put `api.middleware` or `api.doneHandlers`
740 // then the next `Party` will have those updated handlers
741 // but dev may change the rules for that child Party, so we have to make clones of them here.
742
743 var (
744 // global middleware to error handlers as well.
745 beginHandlers = api.beginGlobalHandlers
746 doneHandlers = api.doneGlobalHandlers
747 )
748
749 if errorCode == 0 {
750 beginHandlers = context.JoinHandlers(beginHandlers, api.middleware)
751 doneHandlers = context.JoinHandlers(doneHandlers, api.doneHandlers)
752 } else {
753 beginHandlers = context.JoinHandlers(beginHandlers, api.middlewareErrorCode)
754 }
755
756 // before join the middleware + handlers + done handlers and apply the execution rules.
757
758 mainHandlerName, mainHandlerIndex := context.MainHandlerName(mainHandlers)
759
760 mainHandlerFileName, mainHandlerFileNumber := context.HandlerFileLineRel(mainHandlers[mainHandlerIndex])
761
762 // TODO: think of it.
763 if mainHandlerFileName == "<autogenerated>" {

Callers 2

handleMethod · 0.95
CreateRoutesMethod · 0.95

Calls 12

AnyMethod · 0.95
CopyHandlersFunction · 0.92
GetCallerFunction · 0.92
JoinHandlersFunction · 0.92
MainHandlerNameFunction · 0.92
HandlerFileLineRelFunction · 0.92
statusCodeSuccessfulFunction · 0.85
applyExecutionRulesFunction · 0.85
splitSubdomainAndPathFunction · 0.85
NewRouteFunction · 0.85
ErrorfMethod · 0.80
removeDuplicatesFunction · 0.70

Tested by

no test coverage detected