Chore: Move ReqContext to contexthandler service (#62102)

* Chore: Move ReqContext to contexthandler service

* Rename package to contextmodel

* Generate ngalert files

* Remove unused imports
This commit is contained in:
idafurjes
2023-01-27 08:50:36 +01:00
committed by GitHub
parent 8379a29b53
commit 6c5a573772
180 changed files with 1208 additions and 1182 deletions

View File

@@ -11,7 +11,7 @@ import (
jsoniter "github.com/json-iterator/go"
"github.com/grafana/grafana/pkg/infra/tracing"
"github.com/grafana/grafana/pkg/models"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util/errutil"
)
@@ -19,7 +19,7 @@ import (
// Response is an HTTP response interface.
type Response interface {
// WriteTo writes to a context.
WriteTo(ctx *models.ReqContext)
WriteTo(ctx *contextmodel.ReqContext)
// Body gets the response's body.
Body() []byte
// Status gets the response's status.
@@ -77,7 +77,7 @@ func (r *NormalResponse) ErrMessage() string {
return r.errMessage
}
func (r *NormalResponse) WriteTo(ctx *models.ReqContext) {
func (r *NormalResponse) WriteTo(ctx *contextmodel.ReqContext) {
if r.err != nil {
v := map[string]interface{}{}
traceID := tracing.TraceIDFromContext(ctx.Req.Context(), false)
@@ -132,7 +132,7 @@ func (r StreamingResponse) Body() []byte {
// WriteTo writes the response to the provided context.
// Required to implement api.Response.
func (r StreamingResponse) WriteTo(ctx *models.ReqContext) {
func (r StreamingResponse) WriteTo(ctx *contextmodel.ReqContext) {
header := ctx.Resp.Header()
for k, v := range r.header {
header[k] = v
@@ -155,7 +155,7 @@ type RedirectResponse struct {
}
// WriteTo writes to a response.
func (r *RedirectResponse) WriteTo(ctx *models.ReqContext) {
func (r *RedirectResponse) WriteTo(ctx *contextmodel.ReqContext) {
ctx.Redirect(r.location)
}

View File

@@ -7,17 +7,17 @@ import (
"fmt"
"net/http"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/services/contexthandler/ctxkey"
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
"github.com/grafana/grafana/pkg/web"
)
type (
handlerStd = func(http.ResponseWriter, *http.Request)
handlerStdCtx = func(http.ResponseWriter, *http.Request, *web.Context)
handlerStdReqCtx = func(http.ResponseWriter, *http.Request, *models.ReqContext)
handlerReqCtx = func(*models.ReqContext)
handlerReqCtxRes = func(*models.ReqContext) Response
handlerStdReqCtx = func(http.ResponseWriter, *http.Request, *contextmodel.ReqContext)
handlerReqCtx = func(*contextmodel.ReqContext)
handlerReqCtxRes = func(*contextmodel.ReqContext) Response
handlerCtx = func(*web.Context)
)
@@ -67,11 +67,11 @@ func webCtx(w http.ResponseWriter, r *http.Request) *web.Context {
return ctx
}
func reqCtx(w http.ResponseWriter, r *http.Request) *models.ReqContext {
func reqCtx(w http.ResponseWriter, r *http.Request) *contextmodel.ReqContext {
wCtx := webCtx(w, r)
reqCtx, ok := wCtx.Req.Context().Value(ctxkey.Key{}).(*models.ReqContext)
reqCtx, ok := wCtx.Req.Context().Value(ctxkey.Key{}).(*contextmodel.ReqContext)
if !ok {
panic("no *models.ReqContext found")
panic("no *contextmodel.ReqContext found")
}
return reqCtx
}