Skip to content

OneWay trip doesn't need return date.  #32

Open
@zjplab

Description

Hi thank you for this wonderful project! There are no other free and new flight search apis right now.

One improvement could be to remove the non-necessary returndate for oneway trip.

See here, if you comment out return date there will be an error.

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/krisukox/google-flights-api/flights"
	"golang.org/x/text/currency"
	"golang.org/x/text/language"
)

func main() {
    session, err := flights.New()
    if err != nil {
        log.Fatal(err)
    }

    offers, priceRange, err := session.GetOffers(
        context.Background(),
        flights.Args{
            Date:       time.Now().AddDate(0, 0, 30),
            ReturnDate: time.Now().AddDate(0, 0, 37),
            SrcCities:  []string{"Madrid"},
            DstCities:  []string{"Estocolmo"},
            Options:    flights.Options{
                Travelers: flights.Travelers{Adults: 2},
                Currency:  currency.EUR,
                Stops:     flights.Stop1,
                Class:     flights.Economy,
                TripType:  flights.OneWay,
                Lang:      language.Spanish,
            },
        },
    )
    if err != nil {
        log.Fatal(err)
    }
    
    if priceRange != nil {
        fmt.Printf("High price %d\n", int(priceRange.High))
        fmt.Printf("Low price %d\n", int(priceRange.Low))
    }
    fmt.Println(offers)
}

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions