pkg/web: remove dependency injection (#49123)

* pkg/web: store http.Handler internally

* pkg/web: remove injection

Removes any injection code from pkg/web.

It already was no longer functional, as we already only injected into
`http.Handler`, meaning we only inject ctx.Req and ctx.Resp.

Any other types (*Context, *ReqContext) were already accessed using the
http.Request.Context.Value() method.

* *: remove type mappings

Removes any call to the previously removed TypeMapper, as those were
non-functional already.

* pkg/web: remove Context.Invoke

was no longer used outside of pkg/web and also no longer functional
This commit is contained in:
sh0rez
2022-05-24 15:35:08 -04:00
committed by GitHub
parent 1fcb2f45a6
commit 3ca3a59079
14 changed files with 26 additions and 265 deletions
+3 -4
View File
@@ -33,10 +33,8 @@ func NewServer(t testing.TB, routeRegister routing.RouteRegister) *Server {
m.Use(func(c *web.Context) {
initCtx.Context = c
initCtx.Logger = log.New("api-test")
c.Map(initCtx)
c.Req = c.Req.WithContext(ctxkey.Set(c.Req.Context(), initCtx))
c.Map(c.Req)
})
m.Use(requestContextMiddleware())
@@ -129,7 +127,9 @@ func requestContextFromRequest(req *http.Request) *models.ReqContext {
}
func requestContextMiddleware() web.Handler {
return func(res http.ResponseWriter, req *http.Request, c *models.ReqContext) {
return func(res http.ResponseWriter, req *http.Request) {
c := ctxkey.Get(req.Context()).(*models.ReqContext)
ctx := requestContextFromRequest(req)
if ctx == nil {
c.Next()
@@ -145,6 +145,5 @@ func requestContextMiddleware() web.Handler {
c.RequestNonce = ctx.RequestNonce
c.PerfmonTimer = ctx.PerfmonTimer
c.LookupTokenErr = ctx.LookupTokenErr
c.Map(c)
}
}