mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* 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>
28 lines
557 B
Go
28 lines
557 B
Go
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)
|
|
}
|
|
}
|