func ServiceInstanceStatusHandler(w http.ResponseWriter, r *http.Request, u *auth.User) error { // #TODO (flaviamissi) should check if user has access to service // just call GetServiceInstanceOrError should be enough siName := r.URL.Query().Get(":instance") var si service.ServiceInstance if siName == "" { return &errors.Http{Code: http.StatusBadRequest, Message: "Service instance name not provided."} } conn, err := db.Conn() if err != nil { return err } defer conn.Close() err = conn.ServiceInstances().Find(bson.M{"name": siName}).One(&si) if err != nil { msg := fmt.Sprintf("Service instance does not exists, error: %s", err.Error()) return &errors.Http{Code: http.StatusInternalServerError, Message: msg} } s := si.Service() var b string if b, err = s.ProductionEndpoint().Status(&si); err != nil { msg := fmt.Sprintf("Could not retrieve status of service instance, error: %s", err.Error()) return &errors.Http{Code: http.StatusInternalServerError, Message: msg} } b = fmt.Sprintf(`Service instance "%s" is %s`, siName, b) n, err := w.Write([]byte(b)) if n != len(b) { return &errors.Http{Code: http.StatusInternalServerError, Message: "Failed to write response body"} } return nil }