(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler)
| 836 | } |
| 837 | |
| 838 | func walk(r Routes, walkFn WalkFunc, parentRoute string, parentMw ...func(http.Handler) http.Handler) error { |
| 839 | for _, route := range r.Routes() { |
| 840 | mws := slices.Concat(parentMw, r.Middlewares()) |
| 841 | |
| 842 | if route.SubRoutes != nil { |
| 843 | if handler, ok := route.Handlers["*"]; ok { |
| 844 | if chain, ok := handler.(*ChainHandler); ok { |
| 845 | mws = append(mws, chain.Middlewares...) |
| 846 | } |
| 847 | } |
| 848 | |
| 849 | if err := walk(route.SubRoutes, walkFn, parentRoute+route.Pattern, mws...); err != nil { |
| 850 | return err |
| 851 | } |
| 852 | continue |
| 853 | } |
| 854 | |
| 855 | for method, handler := range route.Handlers { |
| 856 | if method == "*" { |
| 857 | // Ignore a "catchAll" method, since we pass down all the specific methods for each route. |
| 858 | continue |
| 859 | } |
| 860 | |
| 861 | fullRoute := parentRoute + route.Pattern |
| 862 | fullRoute = strings.ReplaceAll(fullRoute, "/*/", "/") |
| 863 | |
| 864 | if chain, ok := handler.(*ChainHandler); ok { |
| 865 | if err := walkFn(method, fullRoute, chain.Endpoint, append(mws, chain.Middlewares...)...); err != nil { |
| 866 | return err |
| 867 | } |
| 868 | } else { |
| 869 | if err := walkFn(method, fullRoute, handler, mws...); err != nil { |
| 870 | return err |
| 871 | } |
| 872 | } |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | return nil |
| 877 | } |
no test coverage detected