Documentation ¶
Overview ¶
Package nasa provides Go structs and functions for accessing the NASA API
Queries are made with Go types as arguments and responses returned as valid Go types. For best experience, grap NASA API key from api.nasa.gov and set it to the environment variable NASAKEY
export NASAKEY=Your-NASA-API_KEY
Example Usage
package main import ( "fmt" "log" "time" "github.com/peteretelej/nasa" ) func main() { apod, err := nasa.ApodImage(time.Now()) handle(err) fmt.Println(apod) // apod has structure of nasa.Image, hence get details with: // apod.Date, apod.Title, apod.Explanation, apod.URL, apod.HDURL etc fmt.Printf("Today's APOD is %s, available at %s", apod.Title, apod.HDURL) lastweek := time.Now().Add(-(7 * 24 * time.Hour)) apod, err = nasa.ApodImage(lastweek) handle(err) fmt.Printf("APOD for 1 week ago:\n%s\n", apod) } func handle(err error) { if err != nil { log.Fatal(err) } }
Index ¶
Constants ¶
const APIKEYMissing = `` /* 203-byte string literal not displayed */
APIKEYMissing is the message displayed if a custom API Key is not defined
Variables ¶
var APODEndpoint = "https://api.nasa.gov/planetary/apod"
APODEndpoint is the NASA API APOD endpoint
var NeoEndpoint = "https://api.nasa.gov/neo/rest/v1/feed"
NeoEndpoint defines the API Endpoint for NASA Neo Web service
Functions ¶
Types ¶
type Asteroid ¶
type Asteroid struct { Links struct{ Self string } ID string `json:"neo_reference_id"` Name string JPLURL string `json:"nasa_jpl_url"` AbsoluteMagnitude float64 `json:"absolute_magnitude_h"` EstimatedDiameter struct { Kilometers, Meters, Miles, Feet diameter } `json:"estimated_diameter"` PotentiallyHazardous bool `json:"is_potentially_hazardous_asteroid"` CloseApproachData []closeApproachData `json:"close_approach_data"` OrbitalData struct { OrbitID string `json:"orbit_id"` OrbitDeterminationDate string `json:"orbit_determination_date"` OrbitUncertainity string `json:"orbit_uncertainty"` MinimumOrbitIntersection string `json:"minimum_orbit_intersection"` JupiterTisserandInvariant string `json:"jupiter_tisserand_invariant"` EpochOsculation string `json:"epoch_osculation"` Eccentricity, Inclination string SemiMajorAxis string `json:"semi_major_axis"` AscendingNodeLongitude string `json:"ascending_node_longitude"` OrbitalPeriod string `json:"orbital_period"` PerihelionDistance string `json:"perihelion_distance"` PerihelionArgument string `json:"perihelion_argument"` AphelionDistance string `json:"aphelion_distance"` PerihelionTime string `json:"perihelion_time"` MeanAnomaly string `json:"mean_anomaly"` MeanMotion string `json:"mean_motion"` Equinox string } `json:"orbital_data"` }
Asteroid defines the structure of NASA Asteroids
type Image ¶
type Image struct { Date string `json:"date"` Title string `json:"title"` URL string `json:"url"` HDURL string `json:"hdurl"` Explanation string `json:"explanation"` ApodDate time.Time `json:",omitempty"` }
Image defines the structure of NASA images
func RandomAPOD ¶
RandomAPOD returns an Astronomy Picture of the Day based on a random date Picks any image shared between the last 2 years
type NeoList ¶
type NeoList struct { Links struct { Self, Next, Prev string } Start string `json:"-"` End string `json:"-"` ElementCount int64 `json:"element_count"` NearEarthObjects map[string][]Asteroid `json:"near_earth_objects"` }
NeoList is the structure of the response returned by NeoWs Feed
type TmplData ¶
type TmplData struct { Page string Title string Apod Image SD bool // Standard definition display AutoReload bool Legacy bool // legacy browser does not support new reload IsYoutube bool AutoReloadInterval int }
TmplData defines the data used to render the html template (tmpl)
func (TmplData) Render ¶
func (td TmplData) Render(wr http.ResponseWriter)
Render returns an html to the responsewriter based on the template data