-
Notifications
You must be signed in to change notification settings - Fork 2
/
apod.go
35 lines (29 loc) · 821 Bytes
/
apod.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package nasa
import (
"encoding/json"
)
const apodAPIURL = "https://api.nasa.gov/planetary/apod"
// APODImage represents an Astronomy Picture Of the Day.
type APODImage struct {
Date Date `json:"date"`
Title string `json:"title"`
URL string `json:"url"`
HDURL string `json:"hdurl"`
Explanation string `json:"explanation"`
MediaType string `json:"media_type"`
Copyright string `json:"copyright"`
ServiceVersion string `json:"service_version"`
}
// APOD returns the Astronomy Picture Of the Day.
func APOD(p ParamEncoder) (APODImage, error) {
content, err := getContent(apodAPIURL, p)
if err != nil {
return APODImage{}, err
}
img := APODImage{}
err = json.Unmarshal(content, &img)
if err != nil {
return APODImage{}, err
}
return img, nil
}