Example #1
0
func callService(w rest.ResponseWriter, r *rest.Request) {
	svc := r.PathParam("backend") + "." + r.PathParam("service")
	var params interface{}
	r.DecodeJsonPayload(&params)

	if _, ok := params.(map[string]interface{}); !ok {
		w.WriteJson(map[string]string{"Error": "Call parameters must be a JSON object"})
		return
	}
	future := service.CallService(svc, params.(map[string]interface{}))

	result := <-future.Result

	switch r := result.(type) {
	case error:
		rest.Error(
			w,
			r.Error(),
			http.StatusInternalServerError,
		)
	default:
		w.WriteJson(r)
	}
}