mirror of
https://github.com/grafana/grafana.git
synced 2025-07-30 23:01:47 +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:
@ -12,16 +12,10 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func Wrap(action interface{}) web.Handler {
|
||||
func Wrap(handler func(c *models.ReqContext) response.Response) web.Handler {
|
||||
return func(c *models.ReqContext) {
|
||||
var res response.Response
|
||||
val, err := c.Invoke(action)
|
||||
if err == nil && val != nil && len(val) > 0 {
|
||||
res = val[0].Interface().(response.Response)
|
||||
} else {
|
||||
res = ServerError(err)
|
||||
if res := handler(c); res != nil {
|
||||
res.WriteTo(c)
|
||||
}
|
||||
|
||||
res.WriteTo(c)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user