Skip to content

Commit 6433ba0

Browse files
lunny6543
andauthored
Move macaron to chi (#14293)
Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <[email protected]>
1 parent 3adbbb4 commit 6433ba0

File tree

353 files changed

+5412
-20734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

353 files changed

+5412
-20734
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ issues:
7070
- path: modules/log/
7171
linters:
7272
- errcheck
73-
- path: routers/routes/macaron.go
73+
- path: routers/routes/web.go
7474
linters:
7575
- dupl
7676
- path: routers/api/v1/repo/issue_subscription.go

cmd/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/storage"
2222
"code.gitea.io/gitea/modules/util"
2323

24-
"gitea.com/macaron/session"
24+
"gitea.com/go-chi/session"
2525
archiver "github.com/mholt/archiver/v3"
2626
"github.com/urfave/cli"
2727
)

cmd/web.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ func runWeb(ctx *cli.Context) error {
102102
return err
103103
}
104104
}
105-
c := routes.NewChi()
106-
routes.RegisterInstallRoute(c)
105+
c := routes.InstallRoutes()
107106
err := listen(c, false)
108107
select {
109108
case <-graceful.GetManager().IsShutdown():
@@ -134,11 +133,9 @@ func runWeb(ctx *cli.Context) error {
134133
return err
135134
}
136135
}
137-
// Set up Chi routes
138-
c := routes.NewChi()
139-
c.Mount("/", routes.NormalRoutes())
140-
routes.DelegateToMacaron(c)
141136

137+
// Set up Chi routes
138+
c := routes.NormalRoutes()
142139
err := listen(c, true)
143140
<-graceful.GetManager().Done()
144141
log.Info("PID: %d Gitea Web Finished", os.Getpid())

contrib/pr/checkout.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ func runPR() {
116116
//routers.GlobalInit()
117117
external.RegisterParsers()
118118
markup.Init()
119-
c := routes.NewChi()
120-
c.Mount("/", routes.NormalRoutes())
121-
routes.DelegateToMacaron(c)
119+
c := routes.NormalRoutes()
122120

123121
log.Printf("[PR] Ready for testing !\n")
124122
log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n")

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
549549

550550
## Session (`session`)
551551

552-
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, nodb, postgres\].
552+
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, postgres\].
553553
- `PROVIDER_CONFIG`: **data/sessions**: For file, the root path; for others, the connection string.
554554
- `COOKIE_SECURE`: **false**: Enable this to force using HTTPS for all session access.
555555
- `COOKIE_NAME`: **i\_like\_gitea**: The name of the cookie used for the session ID.
@@ -609,16 +609,14 @@ Default templates for project boards:
609609
- `MODE`: **console**: Logging mode. For multiple modes, use a comma to separate values. You can configure each mode in per mode log subsections `\[log.modename\]`. By default the file mode will log to `$ROOT_PATH/gitea.log`.
610610
- `LEVEL`: **Info**: General log level. \[Trace, Debug, Info, Warn, Error, Critical, Fatal, None\]
611611
- `STACKTRACE_LEVEL`: **None**: Default log level at which to log create stack traces. \[Trace, Debug, Info, Warn, Error, Critical, Fatal, None\]
612-
- `REDIRECT_MACARON_LOG`: **false**: Redirects the Macaron log to its own logger or the default logger.
613-
- `MACARON`: **file**: Logging mode for the macaron logger, use a comma to separate values. Configure each mode in per mode log subsections `\[log.modename.macaron\]`. By default the file mode will log to `$ROOT_PATH/macaron.log`. (If you set this to `,` it will log to default gitea logger.)
614612
- `ROUTER_LOG_LEVEL`: **Info**: The log level that the router should log at. (If you are setting the access log, its recommended to place this at Debug.)
615613
- `ROUTER`: **console**: The mode or name of the log the router should log to. (If you set this to `,` it will log to default gitea logger.)
616614
NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false` for this option to take effect. Configure each mode in per mode log subsections `\[log.modename.router\]`.
617615
- `ENABLE_ACCESS_LOG`: **false**: Creates an access.log in NCSA common log format, or as per the following template
618616
- `ACCESS`: **file**: Logging mode for the access logger, use a comma to separate values. Configure each mode in per mode log subsections `\[log.modename.access\]`. By default the file mode will log to `$ROOT_PATH/access.log`. (If you set this to `,` it will log to the default gitea logger.)
619617
- `ACCESS_LOG_TEMPLATE`: **`{{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"`**: Sets the template used to create the access log.
620618
- The following variables are available:
621-
- `Ctx`: the `macaron.Context` of the request.
619+
- `Ctx`: the `context.Context` of the request.
622620
- `Identity`: the SignedUserName or `"-"` if not logged in.
623621
- `Start`: the start time of the request.
624622
- `ResponseWriter`: the responseWriter from the request.

docs/content/doc/advanced/logging-documentation.en-us.md

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,11 @@ The provider type of the sublogger can be set using the `MODE` value in
6767
its subsection, but will default to the name. This allows you to have
6868
multiple subloggers that will log to files.
6969

70-
### The "Macaron" logger
71-
72-
By default Macaron will log to its own go `log` instance. This writes
73-
to `os.Stdout`. You can redirect this log to a Gitea configurable logger
74-
through setting the `REDIRECT_MACARON_LOG` setting in the `[log]`
75-
section which you can configure the outputs of by setting the `MACARON`
76-
value in the `[log]` section of the configuration. `MACARON` defaults
77-
to `file` if unset.
78-
79-
Please note, the macaron logger will log at `INFO` level, setting the
80-
`LEVEL` of this logger to `WARN` or above will result in no macaron logs.
81-
82-
Each output sublogger for this logger is configured in
83-
`[log.sublogger.macaron]` sections. There are certain default values
84-
which will not be inherited from the `[log]` or relevant
85-
`[log.sublogger]` sections:
86-
87-
- `FLAGS` is `stdflags` (Equal to
88-
`date,time,medfile,shortfuncname,levelinitial`)
89-
- `FILE_NAME` will default to `%(ROOT_PATH)/macaron.log`
90-
- `EXPRESSION` will default to `""`
91-
- `PREFIX` will default to `""`
92-
93-
NB: You can redirect the macaron logger to send its events to the gitea
94-
log using the value: `MACARON = ,`
95-
9670
### The "Router" logger
9771

98-
There are two types of Router log. By default Macaron send its own
99-
router log which will be directed to Macaron's go `log`, however if you
100-
`REDIRECT_MACARON_LOG` you will enable Gitea's router log. You can
101-
disable both types of Router log by setting `DISABLE_ROUTER_LOG`.
72+
You can disable Router log by setting `DISABLE_ROUTER_LOG`.
10273

103-
If you enable the redirect, you can configure the outputs of this
74+
You can configure the outputs of this
10475
router log by setting the `ROUTER` value in the `[log]` section of the
10576
configuration. `ROUTER` will default to `console` if unset. The Gitea
10677
Router logs the same data as the Macaron log but has slightly different
@@ -162,11 +133,11 @@ This value represent a go template. It's default value is:
162133

163134
The template is passed following options:
164135

165-
- `Ctx` is the `macaron.Context`
136+
- `Ctx` is the `context.Context`
166137
- `Identity` is the `SignedUserName` or `"-"` if the user is not logged
167138
in
168139
- `Start` is the start time of the request
169-
- `ResponseWriter` is the `macaron.ResponseWriter`
140+
- `ResponseWriter` is the `http.ResponseWriter`
170141

171142
Caution must be taken when changing this template as it runs outside of
172143
the standard panic recovery trap. The template should also be as simple

docs/content/page/index.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ Windows, on architectures like amd64, i386, ARM, PowerPC, and others.
267267

268268
## Components
269269

270-
* Web framework: [Macaron](http://go-macaron.com/)
270+
* Web framework: [Chi](http://github.com/go-chi/chi)
271271
* ORM: [XORM](https://xorm.io)
272272
* UI components:
273273
* [Semantic UI](http://semantic-ui.com/)

docs/content/page/index.fr-fr.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Le but de ce projet est de fournir de la manière la plus simple, la plus rapide
254254

255255
## Composants
256256

257-
* Framework web : [Macaron](http://go-macaron.com/)
257+
* Framework web : [Chi](http://github.com/go-chi/chi)
258258
* ORM: [XORM](https://xorm.io)
259259
* Interface graphique :
260260
* [Semantic UI](http://semantic-ui.com/)

docs/content/page/index.zh-cn.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Gitea的首要目标是创建一个极易安装,运行非常快速,安装和
4747

4848
## 组件
4949

50-
* Web框架: [Macaron](http://go-macaron.com/)
50+
* Web框架: [Chi](http://github.com/go-chi/chi)
5151
* ORM: [XORM](https://xorm.io)
5252
* UI组件:
5353
* [Semantic UI](http://semantic-ui.com/)

docs/content/page/index.zh-tw.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Gitea 的首要目標是建立一個容易安裝,運行快速,安装和使
4747

4848
## 元件
4949

50-
* Web 框架: [Macaron](http://go-macaron.com/)
50+
* Web 框架: [Chi](http://github.com/go-chi/chi)
5151
* ORM: [XORM](https://xorm.io)
5252
* UI 元件:
5353
* [Semantic UI](http://semantic-ui.com/)

go.mod

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,12 @@ go 1.14
55
require (
66
code.gitea.io/gitea-vet v0.2.1
77
code.gitea.io/sdk/gitea v0.13.1
8+
gitea.com/go-chi/binding v0.0.0-20210113025129-03f1d313373c
9+
gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e
10+
gitea.com/go-chi/captcha v0.0.0-20210110083842-e7696c336a1e
811
gitea.com/go-chi/session v0.0.0-20210108030337-0cb48c5ba8ee
912
gitea.com/lunny/levelqueue v0.3.0
10-
gitea.com/macaron/binding v0.0.0-20190822013154-a5f53841ed2b
11-
gitea.com/macaron/cache v0.0.0-20200924044943-905232fba10b
12-
gitea.com/macaron/captcha v0.0.0-20200825161008-e8597820aaca
13-
gitea.com/macaron/cors v0.0.0-20190826180238-95aec09ea8b4
14-
gitea.com/macaron/csrf v0.0.0-20190822024205-3dc5a4474439
15-
gitea.com/macaron/gzip v0.0.0-20200827120000-efa5e8477cf5
16-
gitea.com/macaron/i18n v0.0.0-20200911004404-4ca3dd0cbd60
17-
gitea.com/macaron/inject v0.0.0-20190805023432-d4c86e31027a
18-
gitea.com/macaron/macaron v1.5.1-0.20201027213641-0db5d4584804
19-
gitea.com/macaron/session v0.0.0-20201103015045-a177a2701dee
20-
gitea.com/macaron/toolbox v0.0.0-20190822013122-05ff0fc766b7
13+
github.com/NYTimes/gziphandler v1.1.1
2114
github.com/PuerkitoBio/goquery v1.5.1
2215
github.com/RoaringBitmap/roaring v0.5.5 // indirect
2316
github.com/alecthomas/chroma v0.8.2
@@ -36,6 +29,7 @@ require (
3629
github.com/gliderlabs/ssh v0.3.1
3730
github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
3831
github.com/go-chi/chi v1.5.1
32+
github.com/go-chi/cors v1.1.1
3933
github.com/go-enry/go-enry/v2 v2.6.0
4034
github.com/go-git/go-billy/v5 v5.0.0
4135
github.com/go-git/go-git/v5 v5.2.0

0 commit comments

Comments
 (0)