Chore: Moves common and response into separate packages (#30298)

* Chore: moves common and response into separate packages

* Chore: moves common and response into separate packages

* Update pkg/api/utils/common.go

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>

* Chore: changes after PR comments

* Chore: move wrap to routing package

* Chore: move functions in common to response package

* Chore: move functions in common to response package

* Chore: formats imports

Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Hugo Häggmark
2021-01-15 14:43:20 +01:00
committed by GitHub
parent a94c256516
commit 3d41267fc4
51 changed files with 1321 additions and 1248 deletions

View File

@@ -0,0 +1,27 @@
package routing
import (
"github.com/grafana/grafana/pkg/api/response"
"github.com/grafana/grafana/pkg/models"
"gopkg.in/macaron.v1"
)
var (
ServerError = func(err error) response.Response {
return response.Error(500, "Server error", err)
}
)
func Wrap(action interface{}) macaron.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)
}
res.WriteTo(c)
}
}