func CarRequest(w http.ResponseWriter, r *http.Request, p httprouter.Params) { tId := p.ByName("trip_id") checkID, _ := strconv.Atoi(tId) var tripData structure.DataStorage findTarget := false for key, value := range hmap { if key == checkID { tripData = value findTarget = true } } if findTarget == false { w.WriteHeader(404) return } var startLat float64 var startLng float64 var endLat float64 var endLng float64 carRes := structure.CarResponse{} response := structure.Response{} if tripData.Index == 0 { if err := session.DB("cmpe273_project").C("hello").FindId(tripData.Starting_from_location_id).One(&response); err != nil { return } startLat = response.Coordinate.Lat startLng = response.Coordinate.Lng if err := session.DB("cmpe273_project").C("hello").FindId(tripData.Best_route_location_id[0]).One(&response); err != nil { return } endLat = response.Coordinate.Lat endLng = response.Coordinate.Lng uberAPI(&carRes, tripData, startLat, startLng, endLat, endLng) carRes.Status = "requesting" carRes.Starting_from_location_id = tripData.Starting_from_location_id carRes.Next_destination_location_id = tripData.Best_route_location_id[0] } else if tripData.Index == len(tripData.Best_route_location_id) { if err := session.DB("cmpe273_project").C("hello").FindId(tripData.Best_route_location_id[len(tripData.Best_route_location_id)-1]).One(&response); err != nil { return } startLat = response.Coordinate.Lat startLng = response.Coordinate.Lng if err := session.DB("cmpe273_project").C("hello").FindId(tripData.Starting_from_location_id).One(&response); err != nil { return } endLat = response.Coordinate.Lat endLng = response.Coordinate.Lng uberAPI(&carRes, tripData, startLat, startLng, endLat, endLng) carRes.Status = "requesting" carRes.Starting_from_location_id = tripData.Best_route_location_id[len(tripData.Best_route_location_id)-1] carRes.Next_destination_location_id = tripData.Starting_from_location_id } else if tripData.Index > len(tripData.Best_route_location_id) { carRes.Status = "finished" carRes.Starting_from_location_id = tripData.Starting_from_location_id carRes.Next_destination_location_id = tripData.Starting_from_location_id } else { if err := session.DB("cmpe273_project").C("hello").FindId(tripData.Best_route_location_id[tripData.Index-1]).One(&response); err != nil { return } startLat = response.Coordinate.Lat startLng = response.Coordinate.Lng if err := session.DB("cmpe273_project").C("hello").FindId(tripData.Best_route_location_id[tripData.Index]).One(&response); err != nil { return } endLat = response.Coordinate.Lat endLng = response.Coordinate.Lng uberAPI(&carRes, tripData, startLat, startLng, endLat, endLng) carRes.Status = "requesting" carRes.Starting_from_location_id = tripData.Best_route_location_id[tripData.Index-1] carRes.Next_destination_location_id = tripData.Best_route_location_id[tripData.Index] } carRes.Id = tripData.Id carRes.Best_route_location_id = tripData.Best_route_location_id carRes.Total_uber_costs = tripData.Total_uber_costs carRes.Total_uber_duration = tripData.Total_uber_duration carRes.Total_distance = tripData.Total_distance tripData.Index = tripData.Index + 1 hmap[tripData.Id] = tripData trip, _ := json.Marshal(carRes) w.WriteHeader(200) fmt.Fprintf(w, "%s", trip) }