grafana/pkg/api/routing/routing.go
Serge Zaitsev d9cdcb550e
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
2021-11-29 10:18:01 +01:00

22 lines
447 B
Go

package routing
import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/web"
)
var (
ServerError = func(err error) response.Response {
return response.Error(500, "Server error", err)
}
)
func Wrap(handler func(c *models.ReqContext) response.Response) web.Handler {
return func(c *models.ReqContext) {
if res := handler(c); res != nil {
res.WriteTo(c)
}
}
}