loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove redundant "RouteMethods" method (#26024)

The `RouteMethods` is mainly an alias for `Methods` with different
argument order.

Remove it to keep the "route.go" code clear

authored by

wxiaoguang and committed by
GitHub
9b25bfa8 d12ba978

+19 -24
+9 -14
modules/web/route.go
··· 101 101 return middlewares, handlerFunc 102 102 } 103 103 104 - func (r *Route) Methods(method, pattern string, h []any) { 104 + func (r *Route) Methods(method, pattern string, h ...any) { 105 105 middlewares, handlerFunc := r.wrapMiddlewareAndHandler(h) 106 106 fullPattern := r.getPattern(pattern) 107 107 if strings.Contains(method, ",") { ··· 126 126 r.R.With(middlewares...).HandleFunc(r.getPattern(pattern), handlerFunc) 127 127 } 128 128 129 - // RouteMethods delegate special methods, it is an alias of "Methods", while the "pattern" is the first parameter 130 - func (r *Route) RouteMethods(pattern, methods string, h ...any) { 131 - r.Methods(methods, pattern, h) 132 - } 133 - 134 129 // Delete delegate delete method 135 130 func (r *Route) Delete(pattern string, h ...any) { 136 - r.Methods("DELETE", pattern, h) 131 + r.Methods("DELETE", pattern, h...) 137 132 } 138 133 139 134 // Get delegate get method 140 135 func (r *Route) Get(pattern string, h ...any) { 141 - r.Methods("GET", pattern, h) 136 + r.Methods("GET", pattern, h...) 142 137 } 143 138 144 139 // GetOptions delegate get and options method 145 140 func (r *Route) GetOptions(pattern string, h ...any) { 146 - r.Methods("GET,OPTIONS", pattern, h) 141 + r.Methods("GET,OPTIONS", pattern, h...) 147 142 } 148 143 149 144 // PostOptions delegate post and options method 150 145 func (r *Route) PostOptions(pattern string, h ...any) { 151 - r.Methods("POST,OPTIONS", pattern, h) 146 + r.Methods("POST,OPTIONS", pattern, h...) 152 147 } 153 148 154 149 // Head delegate head method 155 150 func (r *Route) Head(pattern string, h ...any) { 156 - r.Methods("HEAD", pattern, h) 151 + r.Methods("HEAD", pattern, h...) 157 152 } 158 153 159 154 // Post delegate post method 160 155 func (r *Route) Post(pattern string, h ...any) { 161 - r.Methods("POST", pattern, h) 156 + r.Methods("POST", pattern, h...) 162 157 } 163 158 164 159 // Put delegate put method 165 160 func (r *Route) Put(pattern string, h ...any) { 166 - r.Methods("PUT", pattern, h) 161 + r.Methods("PUT", pattern, h...) 167 162 } 168 163 169 164 // Patch delegate patch method 170 165 func (r *Route) Patch(pattern string, h ...any) { 171 - r.Methods("PATCH", pattern, h) 166 + r.Methods("PATCH", pattern, h...) 172 167 } 173 168 174 169 // ServeHTTP implements http.Handler
+1 -1
routers/api/packages/api.go
··· 634 634 ) 635 635 636 636 // Manual mapping of routes because {image} can contain slashes which chi does not support 637 - r.RouteMethods("/*", "HEAD,GET,POST,PUT,PATCH,DELETE", func(ctx *context.Context) { 637 + r.Methods("HEAD,GET,POST,PUT,PATCH,DELETE", "/*", func(ctx *context.Context) { 638 638 path := ctx.Params("*") 639 639 isHead := ctx.Req.Method == "HEAD" 640 640 isGet := ctx.Req.Method == "GET"
+1 -1
routers/install/routes.go
··· 20 20 func Routes() *web.Route { 21 21 base := web.NewRoute() 22 22 base.Use(common.ProtocolMiddlewares()...) 23 - base.RouteMethods("/assets/*", "GET, HEAD", public.AssetsHandlerFunc("/assets/")) 23 + base.Methods("GET, HEAD", "/assets/*", public.AssetsHandlerFunc("/assets/")) 24 24 25 25 r := web.NewRoute() 26 26 r.Use(common.Sessioner(), Contexter())
+8 -8
routers/web/web.go
··· 108 108 routes := web.NewRoute() 109 109 110 110 routes.Head("/", misc.DummyOK) // for health check - doesn't need to be passed through gzip handler 111 - routes.RouteMethods("/assets/*", "GET, HEAD", CorsHandler(), public.AssetsHandlerFunc("/assets/")) 112 - routes.RouteMethods("/avatars/*", "GET, HEAD", storageHandler(setting.Avatar.Storage, "avatars", storage.Avatars)) 113 - routes.RouteMethods("/repo-avatars/*", "GET, HEAD", storageHandler(setting.RepoAvatar.Storage, "repo-avatars", storage.RepoAvatars)) 114 - routes.RouteMethods("/apple-touch-icon.png", "GET, HEAD", misc.StaticRedirect("/assets/img/apple-touch-icon.png")) 115 - routes.RouteMethods("/apple-touch-icon-precomposed.png", "GET, HEAD", misc.StaticRedirect("/assets/img/apple-touch-icon.png")) 116 - routes.RouteMethods("/favicon.ico", "GET, HEAD", misc.StaticRedirect("/assets/img/favicon.png")) 111 + routes.Methods("GET, HEAD", "/assets/*", CorsHandler(), public.AssetsHandlerFunc("/assets/")) 112 + routes.Methods("GET, HEAD", "/avatars/*", storageHandler(setting.Avatar.Storage, "avatars", storage.Avatars)) 113 + routes.Methods("GET, HEAD", "/repo-avatars/*", storageHandler(setting.RepoAvatar.Storage, "repo-avatars", storage.RepoAvatars)) 114 + routes.Methods("GET, HEAD", "/apple-touch-icon.png", misc.StaticRedirect("/assets/img/apple-touch-icon.png")) 115 + routes.Methods("GET, HEAD", "/apple-touch-icon-precomposed.png", misc.StaticRedirect("/assets/img/apple-touch-icon.png")) 116 + routes.Methods("GET, HEAD", "/favicon.ico", misc.StaticRedirect("/assets/img/favicon.png")) 117 117 118 118 _ = templates.HTMLRenderer() 119 119 ··· 129 129 130 130 if setting.Service.EnableCaptcha { 131 131 // The captcha http.Handler should only fire on /captcha/* so we can just mount this on that url 132 - routes.RouteMethods("/captcha/*", "GET,HEAD", append(mid, captcha.Captchaer(context.GetImageCaptcha()))...) 132 + routes.Methods("GET,HEAD", "/captcha/*", append(mid, captcha.Captchaer(context.GetImageCaptcha()))...) 133 133 } 134 134 135 135 if setting.HasRobotsTxt { ··· 773 773 addSettingVariablesRoutes() 774 774 }, actions.MustEnableActions) 775 775 776 - m.RouteMethods("/delete", "GET,POST", org.SettingsDelete) 776 + m.Methods("GET,POST", "/delete", org.SettingsDelete) 777 777 778 778 m.Group("/packages", func() { 779 779 m.Get("", org.Packages)