mirror of
https://github.com/grafana/grafana.git
synced 2025-02-09 23:16:16 -06:00
* capitalise logs in observability logs * capitalise oss-bit-tent packages * capitalise logs in aws-datasources * capitalise logs for traces and profiling * capitalise logs for partner datasources * capitalise logs in plugins platform * capitalise logs for observability metrics
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package routes
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/grafana/grafana-plugin-sdk-go/backend/resource/httpadapter"
|
|
|
|
"github.com/grafana/grafana/pkg/infra/log"
|
|
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
|
|
)
|
|
|
|
func ResourceRequestMiddleware(handleFunc models.RouteHandlerFunc, logger log.Logger, reqCtxFactory models.RequestContextFactoryFunc) func(rw http.ResponseWriter, req *http.Request) {
|
|
return func(rw http.ResponseWriter, req *http.Request) {
|
|
if req.Method != "GET" {
|
|
respondWithError(rw, models.NewHttpError("Invalid method", http.StatusMethodNotAllowed, nil))
|
|
return
|
|
}
|
|
|
|
ctx := req.Context()
|
|
pluginContext := httpadapter.PluginConfigFromContext(ctx)
|
|
json, httpError := handleFunc(ctx, pluginContext, reqCtxFactory, req.URL.Query())
|
|
if httpError != nil {
|
|
logger.Error("Error handling resource request", "error", httpError.Message)
|
|
respondWithError(rw, httpError)
|
|
return
|
|
}
|
|
|
|
rw.Header().Set("Content-Type", "application/json")
|
|
_, err := rw.Write(json)
|
|
if err != nil {
|
|
logger.Error("Error handling resource request", "error", err)
|
|
respondWithError(rw, models.NewHttpError("error writing response in resource request middleware", http.StatusInternalServerError, err))
|
|
}
|
|
}
|
|
}
|