| 37 | } |
| 38 | |
| 39 | func serveResponse(w http.ResponseWriter, context map[string]interface{}) { |
| 40 | response := context["response"] |
| 41 | responseCode, ok := context["code"].(int) |
| 42 | if !ok { |
| 43 | responseCode = 200 |
| 44 | } |
| 45 | if 200 <= responseCode && responseCode < 300 { |
| 46 | w.WriteHeader(responseCode) |
| 47 | routes.ServeJson(w, response) |
| 48 | } else { |
| 49 | message := util.MaybeMap(context["exception"]) |
| 50 | middleware.HTTPJSONError(w, message["message"].(string), responseCode) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | func fillInContext(context middleware.Context, |
| 55 | r *http.Request, w http.ResponseWriter, p martini.Params) { |