aboutsummaryrefslogtreecommitdiffstats
path: root/routers/install
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-21 02:49:06 +0800
committerGitHub <noreply@github.com>2023-04-20 14:49:06 -0400
commitb9a97ccd0ea1ee44db85b0fbb80b75255af7c742 (patch)
tree300578dc3c3e62a4cf956ccdc22b8b0ad0cc6036 /routers/install
parent70fc47a22a0bfaef7fb16dcc8a6a2e011b10f8d4 (diff)
downloadgitea-b9a97ccd0ea1ee44db85b0fbb80b75255af7c742.tar.gz
gitea-b9a97ccd0ea1ee44db85b0fbb80b75255af7c742.zip
Refactor web route (#24080)
The old code is unnecessarily complex, and has many misuses. Old code "wraps" a lot, wrap wrap wrap, it's difficult to understand which kind of handler is used. The new code uses a general approach, we do not need to write all kinds of handlers into the "wrapper", do not need to wrap them again and again. New code, there are only 2 concepts: 1. HandlerProvider: `func (h any) (handlerProvider func (next) http.Handler)`, it can be used as middleware 2. Use HandlerProvider to get the final HandlerFunc, and use it for `r.Get()` And we can decouple the route package from context package (see the TODO). # FAQ ## Is `reflect` safe? Yes, all handlers are checked during startup, see the `preCheckHandler` comment. If any handler is wrong, developers could know it in the first time. ## Does `reflect` affect performance? No. https://github.com/go-gitea/gitea/pull/24080#discussion_r1164825901 1. This reflect code only runs for each web handler call, handler is far more slower: 10ms-50ms 2. The reflect is pretty fast (comparing to other code): 0.000265ms 3. XORM has more reflect operations already
Diffstat (limited to 'routers/install')
-rw-r--r--routers/install/routes.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/routers/install/routes.go b/routers/install/routes.go
index df82ba2e4c..f52539ec1b 100644
--- a/routers/install/routes.go
+++ b/routers/install/routes.go
@@ -81,14 +81,14 @@ func installRecovery(ctx goctx.Context) func(next http.Handler) http.Handler {
}
}
-// Routes registers the install routes
+// Routes registers the installation routes
func Routes(ctx goctx.Context) *web.Route {
r := web.NewRoute()
for _, middle := range common.Middlewares() {
r.Use(middle)
}
- r.Use(web.WrapWithPrefix("/assets/", public.AssetsHandlerFunc("/assets/"), "AssetsHandler"))
+ r.Use(web.MiddlewareWithPrefix("/assets/", nil, public.AssetsHandlerFunc("/assets/")))
r.Use(session.Sessioner(session.Options{
Provider: setting.SessionConfig.Provider,
@@ -109,7 +109,7 @@ func Routes(ctx goctx.Context) *web.Route {
r.Get("/post-install", InstallDone)
r.Get("/api/healthz", healthcheck.Check)
- r.NotFound(web.Wrap(installNotFound))
+ r.NotFound(installNotFound)
return r
}