1
1
mirror of https://github.com/go-gitea/gitea synced 2025-08-02 23:58:35 +00:00

Fix context usage (#33554) (#33557)

Backport #33554
This commit is contained in:
wxiaoguang
2025-02-11 19:46:27 +08:00
committed by GitHub
parent 7794ff0874
commit 8fa3925874
6 changed files with 11 additions and 10 deletions

View File

@@ -77,9 +77,9 @@ type webContextKeyType struct{}
var WebContextKey = webContextKeyType{}
func GetWebContext(req *http.Request) *Context {
ctx, _ := req.Context().Value(WebContextKey).(*Context)
return ctx
func GetWebContext(ctx context.Context) *Context {
webCtx, _ := ctx.Value(WebContextKey).(*Context)
return webCtx
}
// ValidateContext is a special context for form validation middleware. It may be different from other contexts.
@@ -133,6 +133,7 @@ func NewWebContext(base *Base, render Render, session session.Store) *Context {
}
ctx.TemplateContext = NewTemplateContextForWeb(ctx)
ctx.Flash = &middleware.Flash{DataStore: ctx, Values: url.Values{}}
ctx.AppendContextValue(WebContextKey, ctx)
return ctx
}