Browse Source
Move macaron to chi (#14293)
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 <6543@obermui.de>mj-v1.14.3
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
353 changed files with 5412 additions and 20734 deletions
-
2.golangci.yml
-
2cmd/dump.go
-
9cmd/web.go
-
4contrib/pr/checkout.go
-
6docs/content/doc/advanced/config-cheat-sheet.en-us.md
-
37docs/content/doc/advanced/logging-documentation.en-us.md
-
2docs/content/page/index.en-us.md
-
2docs/content/page/index.fr-fr.md
-
2docs/content/page/index.zh-cn.md
-
2docs/content/page/index.zh-tw.md
-
16go.mod
-
60go.sum
-
2integrations/api_helper_for_declarative_test.go
-
2integrations/api_pull_test.go
-
8integrations/api_releases_test.go
-
10integrations/create_no_session_test.go
-
11integrations/integration_test.go
-
8integrations/lfs_getobject_test.go
-
3integrations/links_test.go
-
12modules/auth/sso/interface.go
-
2modules/auth/sso/oauth2.go
-
6modules/cache/cache.go
-
2modules/cache/cache_redis.go
-
141modules/context/api.go
-
129modules/context/auth.go
-
26modules/context/captcha.go
-
559modules/context/context.go
-
144modules/context/csrf.go
-
227modules/context/form.go
-
4modules/context/org.go
-
12modules/context/permission.go
-
45modules/context/private.go
-
570modules/context/repo.go
-
29modules/context/response.go
-
100modules/context/secret.go
-
13modules/context/xsrf.go
-
90modules/context/xsrf_test.go
-
25modules/forms/admin.go
-
15modules/forms/auth_form.go
-
24modules/forms/org.go
-
15modules/forms/repo_branch_form.go
-
173modules/forms/repo_form.go
-
2modules/forms/repo_form_test.go
-
108modules/forms/user_form.go
-
24modules/forms/user_form_auth_openid.go
-
2modules/forms/user_form_test.go
-
4modules/lfs/locks.go
-
13modules/lfs/server.go
-
16modules/middlewares/binding.go
-
61modules/middlewares/cookie.go
-
10modules/middlewares/data.go
-
65modules/middlewares/flash.go
-
8modules/middlewares/locale.go
-
217modules/middlewares/redis.go
-
196modules/middlewares/virtual.go
-
2modules/session/redis.go
-
12modules/session/store.go
-
13modules/session/virtual.go
-
12modules/setting/log.go
-
2modules/setting/session.go
-
14modules/templates/base.go
-
25modules/templates/dynamic.go
-
112modules/templates/static.go
-
109modules/test/context_tests.go
-
12modules/timeutil/since_test.go
-
49modules/translation/translation.go
-
2modules/validation/binding.go
-
11modules/validation/binding_test.go
-
2modules/validation/glob_pattern_test.go
-
2modules/validation/refname_test.go
-
2modules/validation/validurl_test.go
-
322modules/web/route.go
-
169modules/web/route_test.go
-
3options/locale/locale_de-DE.ini
-
11routers/admin/admin.go
-
9routers/admin/auths.go
-
9routers/admin/users.go
-
12routers/admin/users_test.go
-
5routers/api/v1/admin/org.go
-
7routers/api/v1/admin/repo.go
-
15routers/api/v1/admin/user.go
-
245routers/api/v1/api.go
-
8routers/api/v1/misc/markdown.go
-
34routers/api/v1/misc/markdown_test.go
-
14routers/api/v1/org/hook.go
-
9routers/api/v1/org/label.go
-
9routers/api/v1/org/org.go
-
9routers/api/v1/org/team.go
-
11routers/api/v1/repo/branch.go
-
5routers/api/v1/repo/collaborators.go
-
6routers/api/v1/repo/commits.go
-
11routers/api/v1/repo/file.go
-
4routers/api/v1/repo/fork.go
-
4routers/api/v1/repo/git_hook.go
-
14routers/api/v1/repo/hook.go
-
12routers/api/v1/repo/issue.go
-
15routers/api/v1/repo/issue_comment.go
-
12routers/api/v1/repo/issue_label.go
-
25routers/api/v1/repo/issue_reaction.go
-
5routers/api/v1/repo/issue_tracked_time.go
@ -0,0 +1,26 @@ |
|||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|||
// Use of this source code is governed by a MIT-style
|
|||
// license that can be found in the LICENSE file.
|
|||
|
|||
package context |
|||
|
|||
import ( |
|||
"sync" |
|||
|
|||
"code.gitea.io/gitea/modules/setting" |
|||
|
|||
"gitea.com/go-chi/captcha" |
|||
) |
|||
|
|||
var imageCaptchaOnce sync.Once |
|||
var cpt *captcha.Captcha |
|||
|
|||
// GetImageCaptcha returns global image captcha
|
|||
func GetImageCaptcha() *captcha.Captcha { |
|||
imageCaptchaOnce.Do(func() { |
|||
cpt = captcha.NewCaptcha(captcha.Options{ |
|||
SubURL: setting.AppSubURL, |
|||
}) |
|||
}) |
|||
return cpt |
|||
} |