aboutsummaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/context/context.go12
-rw-r--r--modules/context/package.go2
-rw-r--r--modules/web/handler.go2
3 files changed, 8 insertions, 8 deletions
diff --git a/modules/context/context.go b/modules/context/context.go
index 1e15081479..9e351432c4 100644
--- a/modules/context/context.go
+++ b/modules/context/context.go
@@ -68,12 +68,12 @@ func (ctx *Context) TrHTMLEscapeArgs(msg string, args ...string) string {
return ctx.Locale.Tr(msg, trArgs...)
}
-type contextKeyType struct{}
+type webContextKeyType struct{}
-var contextKey interface{} = contextKeyType{}
+var WebContextKey = webContextKeyType{}
-func GetContext(req *http.Request) *Context {
- ctx, _ := req.Context().Value(contextKey).(*Context)
+func GetWebContext(req *http.Request) *Context {
+ ctx, _ := req.Context().Value(WebContextKey).(*Context)
return ctx
}
@@ -86,7 +86,7 @@ type ValidateContext struct {
func GetValidateContext(req *http.Request) (ctx *ValidateContext) {
if ctxAPI, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
ctx = &ValidateContext{Base: ctxAPI.Base}
- } else if ctxWeb, ok := req.Context().Value(contextKey).(*Context); ok {
+ } else if ctxWeb, ok := req.Context().Value(WebContextKey).(*Context); ok {
ctx = &ValidateContext{Base: ctxWeb.Base}
} else {
panic("invalid context, expect either APIContext or Context")
@@ -135,7 +135,7 @@ func Contexter() func(next http.Handler) http.Handler {
ctx.PageData = map[string]any{}
ctx.Data["PageData"] = ctx.PageData
- ctx.Base.AppendContextValue(contextKey, ctx)
+ ctx.Base.AppendContextValue(WebContextKey, ctx)
ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo })
ctx.Csrf = PrepareCSRFProtector(csrfOpts, ctx)
diff --git a/modules/context/package.go b/modules/context/package.go
index b1fd7088dd..8052032787 100644
--- a/modules/context/package.go
+++ b/modules/context/package.go
@@ -150,7 +150,7 @@ func PackageContexter() func(next http.Handler) http.Handler {
}
defer baseCleanUp()
- ctx.Base.AppendContextValue(contextKey, ctx)
+ ctx.Base.AppendContextValue(WebContextKey, ctx)
next.ServeHTTP(ctx.Resp, ctx.Req)
})
}
diff --git a/modules/web/handler.go b/modules/web/handler.go
index 5013bac93f..c8aebd9051 100644
--- a/modules/web/handler.go
+++ b/modules/web/handler.go
@@ -22,7 +22,7 @@ type ResponseStatusProvider interface {
// TODO: decouple this from the context package, let the context package register these providers
var argTypeProvider = map[reflect.Type]func(req *http.Request) ResponseStatusProvider{
reflect.TypeOf(&context.APIContext{}): func(req *http.Request) ResponseStatusProvider { return context.GetAPIContext(req) },
- reflect.TypeOf(&context.Context{}): func(req *http.Request) ResponseStatusProvider { return context.GetContext(req) },
+ reflect.TypeOf(&context.Context{}): func(req *http.Request) ResponseStatusProvider { return context.GetWebContext(req) },
reflect.TypeOf(&context.PrivateContext{}): func(req *http.Request) ResponseStatusProvider { return context.GetPrivateContext(req) },
}