Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
705 lines (596 sloc) 27.4 KB
// Code generated from an extremely hacky wsdl tool.
// source: http://flightxml.flightaware.com/soap/FlightXML2/wsdl
// DO NOT EDIT!
package flightaware
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strings"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"go.pedge.io/proto/http"
"golang.org/x/net/context"
"golang.org/x/net/context/ctxhttp"
"google.golang.org/grpc"
)
var (
// DefaultLocalAPIClient is the default local APIClient.
DefaultLocalAPIClient = NewLocalAPIClient(LocalAPIClientOptions{})
// DefaultAPIServer is the default APIServer.
DefaultAPIServer = NewAPIServer(APIServerOptions{})
marshaler = &jsonpb.Marshaler{}
)
// LocalAPIClientOptions are options for a local APIClient.
type LocalAPIClientOptions struct {
HTTPClient *http.Client
}
// NewLocalAPIClient returns a new APIClient that calls Flightaware directly without delegating to an APIServer.
func NewLocalAPIClient(options LocalAPIClientOptions) APIClient {
return newLocalAPIClient(options)
}
type localAPIClient struct {
apiServer APIServer
}
func newLocalAPIClient(options LocalAPIClientOptions) *localAPIClient {
return &localAPIClient{
apiServer: NewAPIServer(
APIServerOptions{
HTTPClient: options.HTTPClient,
},
),
}
}
func (a *localAPIClient) AircraftType(ctx context.Context, request *AircraftTypeRequest, opts ...grpc.CallOption) (*AircraftTypeResults, error) {
return a.apiServer.AircraftType(ctx, request)
}
func (a *localAPIClient) AirlineFlightInfo(ctx context.Context, request *AirlineFlightInfoRequest, opts ...grpc.CallOption) (*AirlineFlightInfoResults, error) {
return a.apiServer.AirlineFlightInfo(ctx, request)
}
func (a *localAPIClient) AirlineFlightSchedules(ctx context.Context, request *AirlineFlightSchedulesRequest, opts ...grpc.CallOption) (*AirlineFlightSchedulesResults, error) {
return a.apiServer.AirlineFlightSchedules(ctx, request)
}
func (a *localAPIClient) AirlineInfo(ctx context.Context, request *AirlineInfoRequest, opts ...grpc.CallOption) (*AirlineInfoResults, error) {
return a.apiServer.AirlineInfo(ctx, request)
}
func (a *localAPIClient) AirlineInsight(ctx context.Context, request *AirlineInsightRequest, opts ...grpc.CallOption) (*AirlineInsightResults, error) {
return a.apiServer.AirlineInsight(ctx, request)
}
func (a *localAPIClient) AirportInfo(ctx context.Context, request *AirportInfoRequest, opts ...grpc.CallOption) (*AirportInfoResults, error) {
return a.apiServer.AirportInfo(ctx, request)
}
func (a *localAPIClient) AllAirlines(ctx context.Context, request *AllAirlinesRequest, opts ...grpc.CallOption) (*AllAirlinesResults, error) {
return a.apiServer.AllAirlines(ctx, request)
}
func (a *localAPIClient) AllAirports(ctx context.Context, request *AllAirportsRequest, opts ...grpc.CallOption) (*AllAirportsResults, error) {
return a.apiServer.AllAirports(ctx, request)
}
func (a *localAPIClient) Arrived(ctx context.Context, request *ArrivedRequest, opts ...grpc.CallOption) (*ArrivedResults, error) {
return a.apiServer.Arrived(ctx, request)
}
func (a *localAPIClient) BlockIdentCheck(ctx context.Context, request *BlockIdentCheckRequest, opts ...grpc.CallOption) (*BlockIdentCheckResults, error) {
return a.apiServer.BlockIdentCheck(ctx, request)
}
func (a *localAPIClient) CountAirportOperations(ctx context.Context, request *CountAirportOperationsRequest, opts ...grpc.CallOption) (*CountAirportOperationsResults, error) {
return a.apiServer.CountAirportOperations(ctx, request)
}
func (a *localAPIClient) CountAllEnrouteAirlineOperations(ctx context.Context, request *CountAllEnrouteAirlineOperationsRequest, opts ...grpc.CallOption) (*CountAllEnrouteAirlineOperationsResults, error) {
return a.apiServer.CountAllEnrouteAirlineOperations(ctx, request)
}
func (a *localAPIClient) DecodeFlightRoute(ctx context.Context, request *DecodeFlightRouteRequest, opts ...grpc.CallOption) (*DecodeFlightRouteResults, error) {
return a.apiServer.DecodeFlightRoute(ctx, request)
}
func (a *localAPIClient) DecodeRoute(ctx context.Context, request *DecodeRouteRequest, opts ...grpc.CallOption) (*DecodeRouteResults, error) {
return a.apiServer.DecodeRoute(ctx, request)
}
func (a *localAPIClient) DeleteAlert(ctx context.Context, request *DeleteAlertRequest, opts ...grpc.CallOption) (*DeleteAlertResults, error) {
return a.apiServer.DeleteAlert(ctx, request)
}
func (a *localAPIClient) Departed(ctx context.Context, request *DepartedRequest, opts ...grpc.CallOption) (*DepartedResults, error) {
return a.apiServer.Departed(ctx, request)
}
func (a *localAPIClient) Enroute(ctx context.Context, request *EnrouteRequest, opts ...grpc.CallOption) (*EnrouteResults, error) {
return a.apiServer.Enroute(ctx, request)
}
func (a *localAPIClient) FleetArrived(ctx context.Context, request *FleetArrivedRequest, opts ...grpc.CallOption) (*FleetArrivedResults, error) {
return a.apiServer.FleetArrived(ctx, request)
}
func (a *localAPIClient) FleetScheduled(ctx context.Context, request *FleetScheduledRequest, opts ...grpc.CallOption) (*FleetScheduledResults, error) {
return a.apiServer.FleetScheduled(ctx, request)
}
func (a *localAPIClient) FlightInfo(ctx context.Context, request *FlightInfoRequest, opts ...grpc.CallOption) (*FlightInfoResults, error) {
return a.apiServer.FlightInfo(ctx, request)
}
func (a *localAPIClient) FlightInfoEx(ctx context.Context, request *FlightInfoExRequest, opts ...grpc.CallOption) (*FlightInfoExResults, error) {
return a.apiServer.FlightInfoEx(ctx, request)
}
func (a *localAPIClient) GetAlerts(ctx context.Context, request *GetAlertsRequest, opts ...grpc.CallOption) (*GetAlertsResults, error) {
return a.apiServer.GetAlerts(ctx, request)
}
func (a *localAPIClient) GetFlightID(ctx context.Context, request *GetFlightIDRequest, opts ...grpc.CallOption) (*GetFlightIDResults, error) {
return a.apiServer.GetFlightID(ctx, request)
}
func (a *localAPIClient) GetHistoricalTrack(ctx context.Context, request *GetHistoricalTrackRequest, opts ...grpc.CallOption) (*GetHistoricalTrackResults, error) {
return a.apiServer.GetHistoricalTrack(ctx, request)
}
func (a *localAPIClient) GetLastTrack(ctx context.Context, request *GetLastTrackRequest, opts ...grpc.CallOption) (*GetLastTrackResults, error) {
return a.apiServer.GetLastTrack(ctx, request)
}
func (a *localAPIClient) InboundFlightInfo(ctx context.Context, request *InboundFlightInfoRequest, opts ...grpc.CallOption) (*InboundFlightInfoResults, error) {
return a.apiServer.InboundFlightInfo(ctx, request)
}
func (a *localAPIClient) InFlightInfo(ctx context.Context, request *InFlightInfoRequest, opts ...grpc.CallOption) (*InFlightInfoResults, error) {
return a.apiServer.InFlightInfo(ctx, request)
}
func (a *localAPIClient) LatLongsToDistance(ctx context.Context, request *LatLongsToDistanceRequest, opts ...grpc.CallOption) (*LatLongsToDistanceResults, error) {
return a.apiServer.LatLongsToDistance(ctx, request)
}
func (a *localAPIClient) LatLongsToHeading(ctx context.Context, request *LatLongsToHeadingRequest, opts ...grpc.CallOption) (*LatLongsToHeadingResults, error) {
return a.apiServer.LatLongsToHeading(ctx, request)
}
func (a *localAPIClient) MapFlight(ctx context.Context, request *MapFlightRequest, opts ...grpc.CallOption) (*MapFlightResults, error) {
return a.apiServer.MapFlight(ctx, request)
}
func (a *localAPIClient) MapFlightEx(ctx context.Context, request *MapFlightExRequest, opts ...grpc.CallOption) (*MapFlightExResults, error) {
return a.apiServer.MapFlightEx(ctx, request)
}
func (a *localAPIClient) Metar(ctx context.Context, request *MetarRequest, opts ...grpc.CallOption) (*MetarResults, error) {
return a.apiServer.Metar(ctx, request)
}
func (a *localAPIClient) MetarEx(ctx context.Context, request *MetarExRequest, opts ...grpc.CallOption) (*MetarExResults, error) {
return a.apiServer.MetarEx(ctx, request)
}
func (a *localAPIClient) NTaf(ctx context.Context, request *NTafRequest, opts ...grpc.CallOption) (*NTafResults, error) {
return a.apiServer.NTaf(ctx, request)
}
func (a *localAPIClient) RegisterAlertEndpoint(ctx context.Context, request *RegisterAlertEndpointRequest, opts ...grpc.CallOption) (*RegisterAlertEndpointResults, error) {
return a.apiServer.RegisterAlertEndpoint(ctx, request)
}
func (a *localAPIClient) RoutesBetweenAirports(ctx context.Context, request *RoutesBetweenAirportsRequest, opts ...grpc.CallOption) (*RoutesBetweenAirportsResults, error) {
return a.apiServer.RoutesBetweenAirports(ctx, request)
}
func (a *localAPIClient) RoutesBetweenAirportsEx(ctx context.Context, request *RoutesBetweenAirportsExRequest, opts ...grpc.CallOption) (*RoutesBetweenAirportsExResults, error) {
return a.apiServer.RoutesBetweenAirportsEx(ctx, request)
}
func (a *localAPIClient) Scheduled(ctx context.Context, request *ScheduledRequest, opts ...grpc.CallOption) (*ScheduledResults, error) {
return a.apiServer.Scheduled(ctx, request)
}
func (a *localAPIClient) Search(ctx context.Context, request *SearchRequest, opts ...grpc.CallOption) (*SearchResults, error) {
return a.apiServer.Search(ctx, request)
}
func (a *localAPIClient) SearchBirdseyeInFlight(ctx context.Context, request *SearchBirdseyeInFlightRequest, opts ...grpc.CallOption) (*SearchBirdseyeInFlightResults, error) {
return a.apiServer.SearchBirdseyeInFlight(ctx, request)
}
func (a *localAPIClient) SearchBirdseyePositions(ctx context.Context, request *SearchBirdseyePositionsRequest, opts ...grpc.CallOption) (*SearchBirdseyePositionsResults, error) {
return a.apiServer.SearchBirdseyePositions(ctx, request)
}
func (a *localAPIClient) SearchCount(ctx context.Context, request *SearchCountRequest, opts ...grpc.CallOption) (*SearchCountResults, error) {
return a.apiServer.SearchCount(ctx, request)
}
func (a *localAPIClient) SetAlert(ctx context.Context, request *SetAlertRequest, opts ...grpc.CallOption) (*SetAlertResults, error) {
return a.apiServer.SetAlert(ctx, request)
}
func (a *localAPIClient) SetMaximumResultSize(ctx context.Context, request *SetMaximumResultSizeRequest, opts ...grpc.CallOption) (*SetMaximumResultSizeResults, error) {
return a.apiServer.SetMaximumResultSize(ctx, request)
}
func (a *localAPIClient) Taf(ctx context.Context, request *TafRequest, opts ...grpc.CallOption) (*TafResults, error) {
return a.apiServer.Taf(ctx, request)
}
func (a *localAPIClient) TailOwner(ctx context.Context, request *TailOwnerRequest, opts ...grpc.CallOption) (*TailOwnerResults, error) {
return a.apiServer.TailOwner(ctx, request)
}
func (a *localAPIClient) ZipcodeInfo(ctx context.Context, request *ZipcodeInfoRequest, opts ...grpc.CallOption) (*ZipcodeInfoResults, error) {
return a.apiServer.ZipcodeInfo(ctx, request)
}
// APIServerOptions are options for a local APIServer.
type APIServerOptions struct {
HTTPClient *http.Client
}
// NewAPIServer returns a new APIServer that calls Flightaware directly.
func NewAPIServer(options APIServerOptions) APIServer {
return newAPIServer(options)
}
type apiServer struct {
httpClient *http.Client
}
func newAPIServer(options APIServerOptions) *apiServer {
apiServer := &apiServer{
httpClient: options.HTTPClient,
}
if apiServer.httpClient == nil {
apiServer.httpClient = http.DefaultClient
}
return apiServer
}
func (a *apiServer) AircraftType(ctx context.Context, request *AircraftTypeRequest) (*AircraftTypeResults, error) {
response := &AircraftTypeResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AircraftType", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AirlineFlightInfo(ctx context.Context, request *AirlineFlightInfoRequest) (*AirlineFlightInfoResults, error) {
response := &AirlineFlightInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AirlineFlightInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AirlineFlightSchedules(ctx context.Context, request *AirlineFlightSchedulesRequest) (*AirlineFlightSchedulesResults, error) {
response := &AirlineFlightSchedulesResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AirlineFlightSchedules", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AirlineInfo(ctx context.Context, request *AirlineInfoRequest) (*AirlineInfoResults, error) {
response := &AirlineInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AirlineInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AirlineInsight(ctx context.Context, request *AirlineInsightRequest) (*AirlineInsightResults, error) {
response := &AirlineInsightResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AirlineInsight", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AirportInfo(ctx context.Context, request *AirportInfoRequest) (*AirportInfoResults, error) {
response := &AirportInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AirportInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AllAirlines(ctx context.Context, request *AllAirlinesRequest) (*AllAirlinesResults, error) {
response := &AllAirlinesResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AllAirlines", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) AllAirports(ctx context.Context, request *AllAirportsRequest) (*AllAirportsResults, error) {
response := &AllAirportsResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/AllAirports", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Arrived(ctx context.Context, request *ArrivedRequest) (*ArrivedResults, error) {
response := &ArrivedResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Arrived", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) BlockIdentCheck(ctx context.Context, request *BlockIdentCheckRequest) (*BlockIdentCheckResults, error) {
response := &BlockIdentCheckResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/BlockIdentCheck", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) CountAirportOperations(ctx context.Context, request *CountAirportOperationsRequest) (*CountAirportOperationsResults, error) {
response := &CountAirportOperationsResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/CountAirportOperations", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) CountAllEnrouteAirlineOperations(ctx context.Context, request *CountAllEnrouteAirlineOperationsRequest) (*CountAllEnrouteAirlineOperationsResults, error) {
response := &CountAllEnrouteAirlineOperationsResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/CountAllEnrouteAirlineOperations", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) DecodeFlightRoute(ctx context.Context, request *DecodeFlightRouteRequest) (*DecodeFlightRouteResults, error) {
response := &DecodeFlightRouteResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/DecodeFlightRoute", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) DecodeRoute(ctx context.Context, request *DecodeRouteRequest) (*DecodeRouteResults, error) {
response := &DecodeRouteResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/DecodeRoute", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) DeleteAlert(ctx context.Context, request *DeleteAlertRequest) (*DeleteAlertResults, error) {
response := &DeleteAlertResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/DeleteAlert", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Departed(ctx context.Context, request *DepartedRequest) (*DepartedResults, error) {
response := &DepartedResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Departed", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Enroute(ctx context.Context, request *EnrouteRequest) (*EnrouteResults, error) {
response := &EnrouteResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Enroute", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) FleetArrived(ctx context.Context, request *FleetArrivedRequest) (*FleetArrivedResults, error) {
response := &FleetArrivedResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/FleetArrived", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) FleetScheduled(ctx context.Context, request *FleetScheduledRequest) (*FleetScheduledResults, error) {
response := &FleetScheduledResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/FleetScheduled", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) FlightInfo(ctx context.Context, request *FlightInfoRequest) (*FlightInfoResults, error) {
response := &FlightInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/FlightInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) FlightInfoEx(ctx context.Context, request *FlightInfoExRequest) (*FlightInfoExResults, error) {
response := &FlightInfoExResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/FlightInfoEx", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) GetAlerts(ctx context.Context, request *GetAlertsRequest) (*GetAlertsResults, error) {
response := &GetAlertsResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/GetAlerts", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) GetFlightID(ctx context.Context, request *GetFlightIDRequest) (*GetFlightIDResults, error) {
response := &GetFlightIDResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/GetFlightID", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) GetHistoricalTrack(ctx context.Context, request *GetHistoricalTrackRequest) (*GetHistoricalTrackResults, error) {
response := &GetHistoricalTrackResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/GetHistoricalTrack", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) GetLastTrack(ctx context.Context, request *GetLastTrackRequest) (*GetLastTrackResults, error) {
response := &GetLastTrackResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/GetLastTrack", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) InboundFlightInfo(ctx context.Context, request *InboundFlightInfoRequest) (*InboundFlightInfoResults, error) {
response := &InboundFlightInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/InboundFlightInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) InFlightInfo(ctx context.Context, request *InFlightInfoRequest) (*InFlightInfoResults, error) {
response := &InFlightInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/InFlightInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) LatLongsToDistance(ctx context.Context, request *LatLongsToDistanceRequest) (*LatLongsToDistanceResults, error) {
response := &LatLongsToDistanceResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/LatLongsToDistance", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) LatLongsToHeading(ctx context.Context, request *LatLongsToHeadingRequest) (*LatLongsToHeadingResults, error) {
response := &LatLongsToHeadingResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/LatLongsToHeading", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) MapFlight(ctx context.Context, request *MapFlightRequest) (*MapFlightResults, error) {
response := &MapFlightResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/MapFlight", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) MapFlightEx(ctx context.Context, request *MapFlightExRequest) (*MapFlightExResults, error) {
response := &MapFlightExResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/MapFlightEx", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Metar(ctx context.Context, request *MetarRequest) (*MetarResults, error) {
response := &MetarResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Metar", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) MetarEx(ctx context.Context, request *MetarExRequest) (*MetarExResults, error) {
response := &MetarExResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/MetarEx", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) NTaf(ctx context.Context, request *NTafRequest) (*NTafResults, error) {
response := &NTafResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/NTaf", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) RegisterAlertEndpoint(ctx context.Context, request *RegisterAlertEndpointRequest) (*RegisterAlertEndpointResults, error) {
response := &RegisterAlertEndpointResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/RegisterAlertEndpoint", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) RoutesBetweenAirports(ctx context.Context, request *RoutesBetweenAirportsRequest) (*RoutesBetweenAirportsResults, error) {
response := &RoutesBetweenAirportsResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/RoutesBetweenAirports", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) RoutesBetweenAirportsEx(ctx context.Context, request *RoutesBetweenAirportsExRequest) (*RoutesBetweenAirportsExResults, error) {
response := &RoutesBetweenAirportsExResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/RoutesBetweenAirportsEx", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Scheduled(ctx context.Context, request *ScheduledRequest) (*ScheduledResults, error) {
response := &ScheduledResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Scheduled", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Search(ctx context.Context, request *SearchRequest) (*SearchResults, error) {
response := &SearchResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Search", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) SearchBirdseyeInFlight(ctx context.Context, request *SearchBirdseyeInFlightRequest) (*SearchBirdseyeInFlightResults, error) {
response := &SearchBirdseyeInFlightResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/SearchBirdseyeInFlight", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) SearchBirdseyePositions(ctx context.Context, request *SearchBirdseyePositionsRequest) (*SearchBirdseyePositionsResults, error) {
response := &SearchBirdseyePositionsResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/SearchBirdseyePositions", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) SearchCount(ctx context.Context, request *SearchCountRequest) (*SearchCountResults, error) {
response := &SearchCountResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/SearchCount", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) SetAlert(ctx context.Context, request *SetAlertRequest) (*SetAlertResults, error) {
response := &SetAlertResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/SetAlert", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) SetMaximumResultSize(ctx context.Context, request *SetMaximumResultSizeRequest) (*SetMaximumResultSizeResults, error) {
response := &SetMaximumResultSizeResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/SetMaximumResultSize", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) Taf(ctx context.Context, request *TafRequest) (*TafResults, error) {
response := &TafResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/Taf", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) TailOwner(ctx context.Context, request *TailOwnerRequest) (*TailOwnerResults, error) {
response := &TailOwnerResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/TailOwner", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) ZipcodeInfo(ctx context.Context, request *ZipcodeInfoRequest) (*ZipcodeInfoResults, error) {
response := &ZipcodeInfoResults{}
if err := a.post(ctx, "https://flightxml.flightaware.com/json/FlightXML2/ZipcodeInfo", request, response); err != nil {
return nil, err
}
return response, nil
}
func (a *apiServer) post(
ctx context.Context,
urlStr string,
request proto.Message,
response proto.Message,
) (retErr error) {
data, err := marshaler.MarshalToString(request)
if err != nil {
return err
}
m := make(map[string]interface{})
if err := json.Unmarshal([]byte(data), &m); err != nil {
return err
}
values := make(url.Values)
for key, value := range m {
values.Add(key, fmt.Sprintf("%v", value))
}
httpRequest, err := http.NewRequest("POST", urlStr, strings.NewReader(values.Encode()))
if err != nil {
return err
}
basicAuth, err := protohttp.BasicAuthFromContext(ctx)
if err != nil {
return err
}
if basicAuth != nil {
httpRequest.SetBasicAuth(basicAuth.Username, basicAuth.Password)
}
httpResponse, err := ctxhttp.Do(ctx, a.httpClient, httpRequest)
if err != nil {
return err
}
defer func() {
if httpResponse.Body != nil {
if err := httpResponse.Body.Close(); err != nil && retErr == nil {
retErr = err
}
}
}()
if httpResponse.StatusCode != http.StatusOK {
return errors.New(httpResponse.Status)
}
body, err := ioutil.ReadAll(httpResponse.Body)
if err != nil {
return err
}
if err := jsonpb.UnmarshalString(string(body), response); err != nil {
s := struct {
Error string
}{}
if uerr := json.Unmarshal(body, &s); uerr == nil {
if s.Error != "" {
return errors.New(s.Error)
}
}
return err
}
return nil
}