mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
27
pkg/api/routing/routing.go
Normal file
27
pkg/api/routing/routing.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user