package main import ( "context" "encoding/json" "fmt" "net/http" "time" standardcovoiturage "git.coopgo.io/coopgo-platform/standard-covoiturage" "gitlab.scity.coop/go-libs/rdex-golang" ) func main() { handler := CarpoolHandler{} server := standardcovoiturage.NewServer(handler) server.AddOperator("fakeoperator", "mysupersecretapikey") http.Handle("/", server) err := http.ListenAndServe(":3333", nil) panic(err) } type CarpoolHandler struct{} func (h CarpoolHandler) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, count *int64) ([]standardcovoiturage.DriverJourney, error) { carpoolrequest := "https://api.rdex.ridygo.fr/journeys.json" client := &http.Client{} req, err := http.NewRequest("GET", carpoolrequest, nil) if err != nil { fmt.Println(err) } req.URL.RawQuery = fmt.Sprintf( "p[driver][state]=1&frequency=punctual&p[passenger][state]=0&p[from][latitude]=%f&p[from][longitude]=%f&p[to][latitude]=%f&p[to][longitude]=%f&p[outward][mindate]=%s&p[outward][maxdate]=%s", departureLat, departureLng, arrivalLat, arrivalLng, departureDate.Format("2006-01-02"), departureDate.Format("2006-01-02")) req.Header.Set("X-API-KEY", "123456") resp, err := client.Do(req) if err != nil { fmt.Println(err) } var carpoolresults []rdex.RDEXJourney if err == nil && resp.StatusCode == http.StatusOK { err = json.NewDecoder(resp.Body).Decode(&carpoolresults) if err != nil { fmt.Println(err) } if carpoolresults == nil { carpoolresults = []rdex.RDEXJourney{} } } else { carpoolresults = []rdex.RDEXJourney{} } results := []standardcovoiturage.DriverJourney{} for _, c := range carpoolresults { journey := standardcovoiturage.DriverJourney{ AvailableSteats: c.Driver.Seats, DriverTrip: standardcovoiturage.DriverTrip{ Trip: standardcovoiturage.Trip{ Operator: c.Operator, WebUrl: c.URL, PassengerPickupLat: c.From.Latitude, PassengerPickupLng: c.From.Longitude, }, Driver: standardcovoiturage.User{ ID: *c.Driver.UUID, Operator: c.Operator, Alias: *c.Driver.Alias, Picture: c.Driver.Image, }, }, } results = append(results, journey) } return results, nil } // func (h CarpoolHandler) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, count *int64) ([]standardcovoiturage.DriverJourney, error) { // availableSeats := int64(1) // return []standardcovoiturage.DriverJourney{ // { // AvailableSteats: &availableSeats, // DriverTrip: standardcovoiturage.DriverTrip{ // Driver: standardcovoiturage.User{ // ID: "1234567890", // Operator: "fakeoperator", // Alias: "Fake user", // }, // Trip: standardcovoiturage.Trip{ // Operator: "fakeoperator", // PassengerPickupLat: 2.0, // PassengerPickupLng: 2.0, // PassengerDropLat: 3.0, // PassengerDropLng: 3.0, // Duration: 3600, // }, // }, // JourneySchedule: standardcovoiturage.JourneySchedule{ // PassengerPickupDate: time.Now(), // Type: standardcovoiturage.Planned, // }, // }, // }, nil // }