mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 05:08:36 +08:00
Chore: Refactor api handlers to use web.Bind (#42199)
* Chore: Refactor api handlers to use web.Bind * fix comments * fix comment * trying to fix most of the tests and force routing.Wrap type check * fix library panels tests * fix frontend logging tests * allow passing nil as a response to skip writing * return nil instead of the response * rewrite login handler function types * remove handlerFuncCtx * make linter happy * remove old bindings from the libraryelements * restore comments
This commit is contained in:
@ -16,11 +16,16 @@ import (
|
||||
"github.com/grafana/grafana/pkg/plugins/adapters"
|
||||
"github.com/grafana/grafana/pkg/tsdb/grafanads"
|
||||
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
// QueryMetricsV2 returns query metrics.
|
||||
// POST /api/ds/query DataSource query w/ expressions
|
||||
func (hs *HTTPServer) QueryMetricsV2(c *models.ReqContext, reqDTO dtos.MetricRequest) response.Response {
|
||||
func (hs *HTTPServer) QueryMetricsV2(c *models.ReqContext) response.Response {
|
||||
reqDTO := dtos.MetricRequest{}
|
||||
if err := web.Bind(c.Req, &reqDTO); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
if len(reqDTO.Queries) == 0 {
|
||||
return response.Error(http.StatusBadRequest, "No queries found in query", nil)
|
||||
}
|
||||
@ -162,7 +167,11 @@ func (hs *HTTPServer) handleGetDataSourceError(err error, datasourceRef interfac
|
||||
|
||||
// QueryMetrics returns query metrics
|
||||
// POST /api/tsdb/query
|
||||
func (hs *HTTPServer) QueryMetrics(c *models.ReqContext, reqDto dtos.MetricRequest) response.Response {
|
||||
func (hs *HTTPServer) QueryMetrics(c *models.ReqContext) response.Response {
|
||||
reqDto := dtos.MetricRequest{}
|
||||
if err := web.Bind(c.Req, &reqDto); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "bad request data", err)
|
||||
}
|
||||
if len(reqDto.Queries) == 0 {
|
||||
return response.Error(http.StatusBadRequest, "No queries found in query", nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user