Calling the API
Now that the project has been set up, we can use the vasystem-api-go
module
to call the API. In this example, we will use the same example values as in the Authentication guide.
Please note that we recommend not hard-coding the values in your code, but instead using environment variables or a configuration file. We have hard-coded them in the example below for simplicity.
Create a file main.go
and add the following:
main.go
package main
import (
"context"
"log"
"time"
vasystemapipb "buf.build/gen/go/vasystem/api/protocolbuffers/go/vasystem/api/v2"
"github.com/vasystem/vasystem-api-go/vasystemapi"
)
func main() {
client, err := vasystemapi.New("staralliancevirtual.org", "client-id", "client-secret")
if err != nil {
log.Fatal(err)
}
airlinesClient := vasystemapi.NewAirlinesServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
airlines, err := client.Airlines().ListAirlines(ctx, &vasystemapipb.ListAirlinesRequest{})
if err != nil {
log.Fatal(err)
}
log.Println(airlines)
}
Replace the example in the vasystem.New
call with the values you
received from the Authentication guide.
You can now run the code with go run main.go
and you should see the following output:
airlines:{id:"..." icao_code:"..." iata_code:".." display_icao_code:"..." display_iata_code:".." name:"..."} airlines:{...} ...