mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 12:12:21 +08:00
More refactoring of user http api, trying to reuse handlers for sign in user and admin operations
This commit is contained in:
@ -26,12 +26,17 @@ type NormalResponse struct {
|
||||
header http.Header
|
||||
}
|
||||
|
||||
func wrap(action func(c *middleware.Context) Response) macaron.Handler {
|
||||
func wrap(action interface{}) macaron.Handler {
|
||||
|
||||
return func(c *middleware.Context) {
|
||||
res := action(c)
|
||||
if res == nil {
|
||||
var res Response
|
||||
val, err := c.Invoke(action)
|
||||
if err == nil && val != nil && len(val) > 0 {
|
||||
res = val[0].Interface().(Response)
|
||||
} else {
|
||||
res = ServerError
|
||||
}
|
||||
|
||||
res.WriteTo(c.Resp)
|
||||
}
|
||||
}
|
||||
@ -64,6 +69,12 @@ func Json(status int, body interface{}) *NormalResponse {
|
||||
return Respond(status, body).Header("Content-Type", "application/json")
|
||||
}
|
||||
|
||||
func ApiSuccess(message string) *NormalResponse {
|
||||
resp := make(map[string]interface{})
|
||||
resp["message"] = message
|
||||
return Respond(200, resp)
|
||||
}
|
||||
|
||||
func ApiError(status int, message string, err error) *NormalResponse {
|
||||
resp := make(map[string]interface{})
|
||||
|
||||
|
Reference in New Issue
Block a user