Introduce go chi web framework as frontend of macaron, so that we can move routes from macaron to chi step by step (#7420)

* When route cannot be found on chi, go to macaron

* Stick chi version to 1.5.0

* Follow router log setting
This commit is contained in:
Lunny Xiao 2020-11-13 20:51:07 +08:00 committed by GitHub
parent 0ae35c66f2
commit c296f4fed6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
49 changed files with 4796 additions and 249 deletions

View file

@ -19,8 +19,6 @@ import (
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/routes"
"gitea.com/macaron/macaron"
context2 "github.com/gorilla/context"
"github.com/unknwon/com"
"github.com/urfave/cli"
@ -135,9 +133,9 @@ func runWeb(ctx *cli.Context) error {
return err
}
}
m := routes.NewMacaron()
routes.RegisterInstallRoute(m)
err := listen(m, false)
c := routes.NewChi()
routes.RegisterInstallRoute(c)
err := listen(c, false)
select {
case <-graceful.GetManager().IsShutdown():
<-graceful.GetManager().Done()
@ -168,10 +166,10 @@ func runWeb(ctx *cli.Context) error {
}
}
// Set up Macaron
m := routes.NewMacaron()
routes.RegisterRoutes(m)
c := routes.NewChi()
routes.RegisterRoutes(c)
err := listen(m, true)
err := listen(c, true)
<-graceful.GetManager().Done()
log.Info("PID: %d Gitea Web Finished", os.Getpid())
log.Close()
@ -212,7 +210,7 @@ func setPort(port string) error {
return nil
}
func listen(m *macaron.Macaron, handleRedirector bool) error {
func listen(m http.Handler, handleRedirector bool) error {
listenAddr := setting.HTTPAddr
if setting.Protocol != setting.UnixSocket && setting.Protocol != setting.FCGIUnix {
listenAddr = net.JoinHostPort(listenAddr, setting.HTTPPort)