1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/spacex/client.go
Chris Cummer f0ca3b8a58
Another actions test (#889)
* Another actions test

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Add BuildTest action

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove lint check for the time being (so many issues)

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix issues found by errcheck

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix errors found by staticcheck

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix issues found by goimports

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Comment out the  action for the time being

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Fix shadowed variables

Signed-off-by: Chris Cummer <chriscummer@me.com>

* go mod tidy

Signed-off-by: Chris Cummer <chriscummer@me.com>

* Remove buildtest.yml

Signed-off-by: Chris Cummer <chriscummer@me.com>

* go mod tidy

Signed-off-by: Chris Cummer <chriscummer@me.com>
2020-05-09 12:51:08 -07:00

52 lines
1.0 KiB
Go

package spacex
import (
"net/http"
"github.com/wtfutil/wtf/utils"
)
const (
spacexLaunchAPI = "https://api.spacexdata.com/v3/launches/next"
)
type Launch struct {
FlightNumber int `json:"flight_number"`
MissionName string `json:"mission_name"`
LaunchDate int64 `json:"launch_date_unix"`
IsTentative bool `json:"tentative"`
Rocket Rocket `json:"rocket"`
LaunchSite LaunchSite `json:"launch_site"`
Links Links `json:"links"`
Details string `json:"details"`
}
type LaunchSite struct {
Name string `json:"site_name_long"`
}
type Rocket struct {
Name string `json:"rocket_name"`
}
type Links struct {
RedditLink string `json:"reddit_campaign"`
YouTubeLink string `json:"video_link"`
}
func NextLaunch() (*Launch, error) {
resp, err := http.Get(spacexLaunchAPI)
if err != nil {
return nil, err
}
defer func() { _ = resp.Body.Close() }()
var data Launch
err = utils.ParseJSON(&data, resp.Body)
if err != nil {
return nil, err
}
return &data, nil
}