spacex

package module
v0.0.0-...-1035c6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

spacex CircleCI GoDoc

Go client library for the SpaceX REST API developed at r-spacex. Because Rockets are cool.

Space Gophers Animated Gif

image credit:

Using this client library, you could get information about things like the date of the next launch, videos / stats about previous launches, data about different rockets and capsules, live stats about the roadster/star man, etc.

Supported Entities/Endpoints

Rate-limiting is supported natively (use NewWithRateLimit). Set a rate limit of 50 to comply with the REST API's spec.

TODO:
  • Capsule Details
  • Launchpads

Usage Example

Space Gophers Animated Gif

Get info about falcon9 rocket (check out the client_test.go file for more examples):

c := New()
rocket, err := c.GetRocket("falcon9")
if err != nil {
    log.Fatal(err)
}

Result:

{
  "rocketid": 2,
  "id": "falcon9",
  "name": "Falcon 9",
  "type": "rocket",
  "active": true,
  "stages": 2,
  "boosters": 0,
  "cost_per_launch": 50000000,
  "success_rate_pct": 97,
  "first_flight": "2010-06-04",
  "country": "United States",
  "company": "SpaceX",
  "height": {
    "meters": 70,
    "feet": 229.6
  },
  "diameter": {
    "meters": 3.7,
    "feet": 12
  },
  "mass": {
    "kg": 549054,
    "lb": 1207920
  },
  "payload_weights": [
    {
      "id": "leo",
      "name": "Low Earth Orbit",
      "kg": 22800,
      "lb": 50265
    },
    {
      "id": "gto",
      "name": "Geosynchronous Transfer Orbit",
      "kg": 8300,
      "lb": 18300
    },
    {
      "id": "mars",
      "name": "Mars Orbit",
      "kg": 4020,
      "lb": 8860
    }
  ],
  "first_stage": {
    "reusable": true,
    "engines": 9,
    "fuel_amount_tons": 385,
    "burn_time_sec": 162,
    "thrust_sea_level": {
      "kN": 7607,
      "lbf": 1710000
    },
    "thrust_vacuum": {
      "kN": 8227,
      "lbf": 1849500
    }
  },
  "second_stage": {
    "engines": 1,
    "fuel_amount_tons": 90,
    "burn_time_sec": 397,
    "thrust": {
      "kN": 934,
      "lbf": 210000
    },
    "payloads": {
      "option_1": "dragon",
      "option_2": "composite fairing",
      "composite_fairing": {
        "height": {
          "meters": 13.1,
          "feet": 43
        },
        "diameter": {
          "meters": 5.2,
          "feet": 17.1
        }
      }
    }
  },
  "engines": {
    "number": 9,
    "type": "merlin",
    "version": "1D+",
    "layout": "octaweb",
    "engine_loss_max": 2,
    "propellant_1": "liquid oxygen",
    "propellant_2": "RP-1 kerosene",
    "thrust_sea_level": {
      "kN": 845,
      "lbf": 190000
    },
    "thrust_vacuum": {
      "kN": 914,
      "lbf": 205500
    },
    "thrust_to_weight": 180.1
  },
  "landing_legs": {
    "number": 4,
    "material": "carbon fiber"
  },
  "wikipedia": "https://en.wikipedia.org/wiki/Falcon_9",
  "description": "Falcon 9 is a two-stage rocket designed and manufactured by SpaceX for the reliable and safe transport of satellites and the Dragon spacecraft into orbit."
}

Documentation

Index

Constants

View Source
const (
	LaunchTypePast     = LaunchType(3)
	LaunchTypeUpcoming = LaunchType(4)
	LaunchTypeAll      = LaunchType(5)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Capsule

type Capsule struct {
	ID               string  `json:"id"`
	Name             string  `json:"name"`
	Type             string  `json:"type"`
	Active           bool    `json:"active"`
	CrewCapacity     float64 `json:"crew_capacity"`
	SidewallAngleDeg float64 `json:"sidewall_angle_deg"`
	OrbitDurationYr  float64 `json:"orbit_duration_yr"`
	HeatShield       struct {
		Material    string  `json:"material"`
		SizeMeters  float64 `json:"size_meters"`
		TempDegrees float64 `json:"temp_degrees"`
		DevPartner  string  `json:"dev_partner"`
	} `json:"heat_shield"`
	Thrusters []struct {
		Type   string  `json:"type"`
		Amount float64 `json:"amount"`
		Pods   float64 `json:"pods"`
		Fuel1  string  `json:"fuel_1"`
		Fuel2  string  `json:"fuel_2"`
		Thrust struct {
			KN  float64 `json:"kN"`
			Lbf float64 `json:"lbf"`
		} `json:"thrust"`
	} `json:"thrusters"`
	LaunchPayloadMass struct {
		Kg float64 `json:"kg"`
		Lb float64 `json:"lb"`
	} `json:"launch_payload_mass"`
	LaunchPayloadVol struct {
		CubicMeters float64 `json:"cubic_meters"`
		CubicFeet   float64 `json:"cubic_feet"`
	} `json:"launch_payload_vol"`
	ReturnPayloadMass struct {
		Kg float64 `json:"kg"`
		Lb float64 `json:"lb"`
	} `json:"return_payload_mass"`
	ReturnPayloadVol struct {
		CubicMeters float64 `json:"cubic_meters"`
		CubicFeet   float64 `json:"cubic_feet"`
	} `json:"return_payload_vol"`
	PressurizedCapsule struct {
		PayloadVolume struct {
			CubicMeters float64 `json:"cubic_meters"`
			CubicFeet   float64 `json:"cubic_feet"`
		} `json:"payload_volume"`
	} `json:"pressurized_capsule"`
	Trunk struct {
		TrunkVolume struct {
			CubicMeters float64 `json:"cubic_meters"`
			CubicFeet   float64 `json:"cubic_feet"`
		} `json:"trunk_volume"`
		Cargo struct {
			SolarArray         float64 `json:"solar_array"`
			UnpressurizedCargo bool    `json:"unpressurized_cargo"`
		} `json:"cargo"`
	} `json:"trunk"`
	HeightWTrunk struct {
		Meters float64 `json:"meters"`
		Feet   float64 `json:"feet"`
	} `json:"height_w_trunk"`
	Diameter struct {
		Meters float64 `json:"meters"`
		Feet   float64 `json:"feet"`
	} `json:"diameter"`
	Wikipedia   string `json:"wikipedia"`
	Description string `json:"description"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New() *Client

New creates a new spacex client

func NewWithRateLimit

func NewWithRateLimit(rl int) (*Client, error)

func (*Client) GetAllCapsules

func (c *Client) GetAllCapsules() ([]*Capsule, error)

GetAllCapsules returns all Capsules info

func (*Client) GetAllRockets

func (c *Client) GetAllRockets() ([]*Rocket, error)

GetAllRockets returns all rockets info

func (*Client) GetCapsule

func (c *Client) GetCapsule(name string) (*Capsule, error)

GetCapsule returns Capsule info by name

func (*Client) GetHistory

func (c *Client) GetHistory(filters map[string]interface{}) ([]*History, error)

GetHistory returns historical events according to filters

func (*Client) GetInfo

func (c *Client) GetInfo() (*Info, error)

GetInfo returns comapny info

func (*Client) GetLatestLaunch

func (c *Client) GetLatestLaunch() (*Launch, error)

GetLatestLaunch returns the latest launch

func (*Client) GetLaunches

func (c *Client) GetLaunches(launchType LaunchType, filters map[string]interface{}) ([]*Launch, error)

GetLaunches returns launches according to launch type and filters

func (*Client) GetNextLaunch

func (c *Client) GetNextLaunch() (*Launch, error)

GetNextLaunch returns the next launch“

func (*Client) GetObjectInfo

func (c *Client) GetObjectInfo(name string) (*ObjectInfo, error)

GetObjectInfo returns object info by name

func (*Client) GetRocket

func (c *Client) GetRocket(name string) (*Rocket, error)

GetRocket returns rocket info by name

type History

type History struct {
	Title         string    `json:"title"`
	EventDateUtc  time.Time `json:"event_date_utc"`
	EventDateUnix int       `json:"event_date_unix"`
	FlightNumber  int       `json:"flight_number"`
	Details       string    `json:"details"`
	Links         struct {
		Reddit    string `json:"reddit"`
		Article   string `json:"article"`
		Wikipedia string `json:"wikipedia"`
	} `json:"links"`
}

type Info

type Info struct {
	Name          string `json:"name"`
	Founder       string `json:"founder"`
	Founded       int    `json:"founded"`
	Employees     int    `json:"employees"`
	Vehicles      int    `json:"vehicles"`
	LaunchSites   int    `json:"launch_sites"`
	TestSites     int    `json:"test_sites"`
	Ceo           string `json:"ceo"`
	Cto           string `json:"cto"`
	Coo           string `json:"coo"`
	CtoPropulsion string `json:"cto_propulsion"`
	Valuation     int64  `json:"valuation"`
	Headquarters  struct {
		Address string `json:"address"`
		City    string `json:"city"`
		State   string `json:"state"`
	} `json:"headquarters"`
	Summary string `json:"summary"`
}

type Launch

type Launch struct {
	FlightNumber    float64   `json:"flight_number"`
	MissionName     string    `json:"mission_name"`
	LaunchYear      string    `json:"launch_year"`
	LaunchDateUnix  float64   `json:"launch_date_unix"`
	LaunchDateUtc   time.Time `json:"launch_date_utc"`
	LaunchDateLocal string    `json:"launch_date_local"`
	Rocket          struct {
		RocketID   string `json:"rocket_id"`
		RocketName string `json:"rocket_name"`
		RocketType string `json:"rocket_type"`
		FirstStage struct {
			Cores []struct {
				CoreSerial     string  `json:"core_serial"`
				Flight         float64 `json:"flight"`
				Block          float64 `json:"block"`
				Reused         bool    `json:"reused"`
				LandSuccess    bool    `json:"land_success"`
				LandingType    string  `json:"landing_type"`
				LandingVehicle string  `json:"landing_vehicle"`
			} `json:"cores"`
		} `json:"first_stage"`
		SecondStage struct {
			Block    float64 `json:"block"`
			Payloads []struct {
				PayloadID      string    `json:"payload_id"`
				NoradID        []float64 `json:"norad_id"`
				Reused         bool      `json:"reused"`
				Customers      []string  `json:"customers"`
				Nationality    string    `json:"nationality"`
				Manufacturer   string    `json:"manufacturer"`
				PayloadType    string    `json:"payload_type"`
				PayloadMassKg  float64   `json:"payload_mass_kg"`
				PayloadMassLbs float64   `json:"payload_mass_lbs"`
				Orbit          string    `json:"orbit"`
				OrbitParams    struct {
					ReferenceSystem string    `json:"reference_system"`
					Regime          string    `json:"regime"`
					Longitude       float64   `json:"longitude"`
					SemiMajorAxisKm float64   `json:"semi_major_axis_km"`
					Eccentricity    float64   `json:"eccentricity"`
					PeriapsisKm     float64   `json:"periapsis_km"`
					ApoapsisKm      float64   `json:"apoapsis_km"`
					InclinationDeg  float64   `json:"inclination_deg"`
					PeriodMin       float64   `json:"period_min"`
					LifespanYears   float64   `json:"lifespan_years"`
					Epoch           time.Time `json:"epoch"`
					MeanMotion      float64   `json:"mean_motion"`
					Raan            float64   `json:"raan"`
				} `json:"orbit_params"`
			} `json:"payloads"`
		} `json:"second_stage"`
	} `json:"rocket"`
	Telemetry struct {
		FlightClub interface{} `json:"flight_club"`
	} `json:"telemetry"`
	Reuse struct {
		Core      bool `json:"core"`
		SideCore1 bool `json:"side_core1"`
		SideCore2 bool `json:"side_core2"`
		Fairings  bool `json:"fairings"`
		Capsule   bool `json:"capsule"`
	} `json:"reuse"`
	LaunchSite struct {
		SiteID       string `json:"site_id"`
		SiteName     string `json:"site_name"`
		SiteNameLong string `json:"site_name_long"`
	} `json:"launch_site"`
	LaunchSuccess bool `json:"launch_success"`
	Links         struct {
		MissionPatch      string      `json:"mission_patch"`
		MissionPatchSmall string      `json:"mission_patch_small"`
		RedditCampaign    string      `json:"reddit_campaign"`
		RedditLaunch      string      `json:"reddit_launch"`
		RedditRecovery    interface{} `json:"reddit_recovery"`
		RedditMedia       string      `json:"reddit_media"`
		Presskit          string      `json:"presskit"`
		ArticleLink       string      `json:"article_link"`
		Wikipedia         string      `json:"wikipedia"`
		VideoLink         string      `json:"video_link"`
	} `json:"links"`
	Details           string    `json:"details"`
	Upcoming          bool      `json:"upcoming"`
	StaticFireDateUtc time.Time `json:"static_fire_date_utc"`
}

type LaunchType

type LaunchType int

type ObjectInfo

type ObjectInfo struct {
	Name            string    `json:"name"`
	LaunchDateUtc   time.Time `json:"launch_date_utc"`
	LaunchDateUnix  int       `json:"launch_date_unix"`
	LaunchMassKg    float64   `json:"launch_mass_kg"`
	LaunchMassLbs   float64   `json:"launch_mass_lbs"`
	NoradID         float64   `json:"norad_id"`
	EpochJd         string    `json:"epoch_jd"`
	OrbitType       string    `json:"orbit_type"`
	ApoapsisAu      float64   `json:"apoapsis_au"`
	PeriapsisAu     float64   `json:"periapsis_au"`
	SemiMajorAxisAu float64   `json:"semi_major_axis_au"`
	Eccentricity    float64   `json:"eccentricity"`
	Inclination     float64   `json:"inclination"`
	Longitude       float64   `json:"longitude"`
	PeriapsisArg    float64   `json:"periapsis_arg"`
	PeriodDays      float64   `json:"period_days"`
	SpeedKph        float64   `json:"speed_kph"`
	SpeedMph        float64   `json:"speed_mph"`
	EarthDistanceKm float64   `json:"earth_distance_km"`
	EarthDistanceMi float64   `json:"earth_distance_mi"`
	MarsDistanceKm  float64   `json:"mars_distance_km"`
	MarsDistanceMi  float64   `json:"mars_distance_mi"`
	Wikipedia       string    `json:"wikipedia"`
	Details         string    `json:"details"`
}

type Rocket

type Rocket struct {
	Rocketid       float64 `json:"rocketid"`
	ID             string  `json:"id"`
	Name           string  `json:"name"`
	Type           string  `json:"type"`
	Active         bool    `json:"active"`
	Stages         float64 `json:"stages"`
	Boosters       float64 `json:"boosters"`
	CostPerLaunch  float64 `json:"cost_per_launch"`
	SuccessRatePct float64 `json:"success_rate_pct"`
	FirstFlight    string  `json:"first_flight"`
	Country        string  `json:"country"`
	Company        string  `json:"company"`
	Height         struct {
		Meters float64 `json:"meters"`
		Feet   float64 `json:"feet"`
	} `json:"height"`
	Diameter struct {
		Meters float64 `json:"meters"`
		Feet   float64 `json:"feet"`
	} `json:"diameter"`
	Mass struct {
		Kg float64 `json:"kg"`
		Lb float64 `json:"lb"`
	} `json:"mass"`
	PayloadWeights []struct {
		ID   string  `json:"id"`
		Name string  `json:"name"`
		Kg   float64 `json:"kg"`
		Lb   float64 `json:"lb"`
	} `json:"payload_weights"`
	FirstStage struct {
		Reusable       bool    `json:"reusable"`
		Engines        float64 `json:"engines"`
		FuelAmountTons float64 `json:"fuel_amount_tons"`
		BurnTimeSec    float64 `json:"burn_time_sec"`
		ThrustSeaLevel struct {
			KN  float64 `json:"kN"`
			Lbf float64 `json:"lbf"`
		} `json:"thrust_sea_level"`
		ThrustVacuum struct {
			KN  float64 `json:"kN"`
			Lbf float64 `json:"lbf"`
		} `json:"thrust_vacuum"`
	} `json:"first_stage"`
	SecondStage struct {
		Engines        float64 `json:"engines"`
		FuelAmountTons float64 `json:"fuel_amount_tons"`
		BurnTimeSec    float64 `json:"burn_time_sec"`
		Thrust         struct {
			KN  float64 `json:"kN"`
			Lbf float64 `json:"lbf"`
		} `json:"thrust"`
		Payloads struct {
			Option1          string `json:"option_1"`
			Option2          string `json:"option_2"`
			CompositeFairing struct {
				Height struct {
					Meters float64 `json:"meters"`
					Feet   float64 `json:"feet"`
				} `json:"height"`
				Diameter struct {
					Meters float64 `json:"meters"`
					Feet   float64 `json:"feet"`
				} `json:"diameter"`
			} `json:"composite_fairing"`
		} `json:"payloads"`
	} `json:"second_stage"`
	Engines struct {
		Number         float64 `json:"number"`
		Type           string  `json:"type"`
		Version        string  `json:"version"`
		Layout         string  `json:"layout"`
		EngineLossMax  float64 `json:"engine_loss_max"`
		Propellant1    string  `json:"propellant_1"`
		Propellant2    string  `json:"propellant_2"`
		ThrustSeaLevel struct {
			KN  float64 `json:"kN"`
			Lbf float64 `json:"lbf"`
		} `json:"thrust_sea_level"`
		ThrustVacuum struct {
			KN  float64 `json:"kN"`
			Lbf float64 `json:"lbf"`
		} `json:"thrust_vacuum"`
		ThrustToWeight float64 `json:"thrust_to_weight"`
	} `json:"engines"`
	LandingLegs struct {
		Number   float64 `json:"number"`
		Material string  `json:"material"`
	} `json:"landing_legs"`
	Wikipedia   string `json:"wikipedia"`
	Description string `json:"description"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL