Skip to content

Commit 9b25bfa

Browse files
authored
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
1 parent d12ba97 commit 9b25bfa

File tree

4 files changed

+19
-24
lines changed

4 files changed

+19
-24
lines changed

modules/web/route.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (r *Route) wrapMiddlewareAndHandler(h []any) ([]func(http.Handler) http.Han
101101
return middlewares, handlerFunc
102102
}
103103

104-
func (r *Route) Methods(method, pattern string, h []any) {
104+
func (r *Route) Methods(method, pattern string, h ...any) {
105105
middlewares, handlerFunc := r.wrapMiddlewareAndHandler(h)
106106
fullPattern := r.getPattern(pattern)
107107
if strings.Contains(method, ",") {
@@ -126,49 +126,44 @@ func (r *Route) Any(pattern string, h ...any) {
126126
r.R.With(middlewares...).HandleFunc(r.getPattern(pattern), handlerFunc)
127127
}
128128

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-
134129
// Delete delegate delete method
135130
func (r *Route) Delete(pattern string, h ...any) {
136-
r.Methods("DELETE", pattern, h)
131+
r.Methods("DELETE", pattern, h...)
137132
}
138133

139134
// Get delegate get method
140135
func (r *Route) Get(pattern string, h ...any) {
141-
r.Methods("GET", pattern, h)
136+
r.Methods("GET", pattern, h...)
142137
}
143138

144139
// GetOptions delegate get and options method
145140
func (r *Route) GetOptions(pattern string, h ...any) {
146-
r.Methods("GET,OPTIONS", pattern, h)
141+
r.Methods("GET,OPTIONS", pattern, h...)
147142
}
148143

149144
// PostOptions delegate post and options method
150145
func (r *Route) PostOptions(pattern string, h ...any) {
151-
r.Methods("POST,OPTIONS", pattern, h)
146+
r.Methods("POST,OPTIONS", pattern, h...)
152147
}
153148

154149
// Head delegate head method
155150
func (r *Route) Head(pattern string, h ...any) {
156-
r.Methods("HEAD", pattern, h)
151+
r.Methods("HEAD", pattern, h...)
157152
}
158153

159154
// Post delegate post method
160155
func (r *Route) Post(pattern string, h ...any) {
161-
r.Methods("POST", pattern, h)
156+
r.Methods("POST", pattern, h...)
162157
}
163158

164159
// Put delegate put method
165160
func (r *Route) Put(pattern string, h ...any) {
166-
r.Methods("PUT", pattern, h)
161+
r.Methods("PUT", pattern, h...)
167162
}
168163

169164
// Patch delegate patch method
170165
func (r *Route) Patch(pattern string, h ...any) {
171-
r.Methods("PATCH", pattern, h)
166+
r.Methods("PATCH", pattern, h...)
172167
}
173168

174169
// ServeHTTP implements http.Handler

routers/api/packages/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ func ContainerRoutes() *web.Route {
634634
)
635635

636636
// 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) {
638638
path := ctx.Params("*")
639639
isHead := ctx.Req.Method == "HEAD"
640640
isGet := ctx.Req.Method == "GET"

routers/install/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
func Routes() *web.Route {
2121
base := web.NewRoute()
2222
base.Use(common.ProtocolMiddlewares()...)
23-
base.RouteMethods("/assets/*", "GET, HEAD", public.AssetsHandlerFunc("/assets/"))
23+
base.Methods("GET, HEAD", "/assets/*", public.AssetsHandlerFunc("/assets/"))
2424

2525
r := web.NewRoute()
2626
r.Use(common.Sessioner(), Contexter())

routers/web/web.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ func Routes() *web.Route {
108108
routes := web.NewRoute()
109109

110110
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"))
117117

118118
_ = templates.HTMLRenderer()
119119

@@ -129,7 +129,7 @@ func Routes() *web.Route {
129129

130130
if setting.Service.EnableCaptcha {
131131
// 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()))...)
133133
}
134134

135135
if setting.HasRobotsTxt {
@@ -773,7 +773,7 @@ func registerRoutes(m *web.Route) {
773773
addSettingVariablesRoutes()
774774
}, actions.MustEnableActions)
775775

776-
m.RouteMethods("/delete", "GET,POST", org.SettingsDelete)
776+
m.Methods("GET,POST", "/delete", org.SettingsDelete)
777777

778778
m.Group("/packages", func() {
779779
m.Get("", org.Packages)

0 commit comments

Comments
 (0)