(errorCode int, methods []string, relativePath string, handlers ...context.Handler)
| 704 | } |
| 705 | |
| 706 | func (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>" { |
no test coverage detected