Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorDateNotFound is returned when given date is not found on the NASA API ErrorDateNotFound = fmt.Errorf("date not found in NASA API") // ErrorDateInvalid is returned when given date is not in the correct format ErrorDateInvalid = fmt.Errorf("date is not in the correct format, use yyyy-mm-dd") )
Functions ¶
func IsValidDate ¶
IsValidDate checks if a date is formatted correctly and occurs after the first published APOD
func NewImageCache ¶
func NewImageCache(dir string) *cache.FSCache[*ImageWrapper]
NewImageCache simplifies the creation of an APOD image cache
Types ¶
type APOD ¶
type APOD struct {
// contains filtered or unexported fields
}
APOD is a client for the NASA APOD API
It maintains a cache for APOD responses and an image cache for images.
func NewClient ¶
func NewClient(key string, cache cache.Cache[*Response], imageCache cache.Cache[*ImageWrapper]) *APOD
NewClient creates a new APOD client
func (*APOD) Fill ¶
func (a *APOD) Fill()
Fill runs in the background and fills the cache with _ALL_ APOD responses from the NASA API
func (*APOD) Get ¶
Get the APOD response for a specific date
Uses the cache if the response is already stored
func (*APOD) GetImage ¶
func (a *APOD) GetImage(day string) (*ImageWrapper, error)
GetImage returns the image for a specific day
type ImageWrapper ¶
type ImageWrapper struct {
// Image is the decoded image
Image image.Image
// Format is the image format (png, jpg, etc.)
Format string
// Bytes is the binary representation of the image
Bytes []byte
}
ImageWrapper is a wrapper around an image.Image that caches the image's binary representation and format.
This is useful for caching images in memory
func NewImageWrapper ¶
func NewImageWrapper(buf []byte) (*ImageWrapper, error)
NewImageWrapper creates a new ImageWrapper from binary data.
func (*ImageWrapper) Resize ¶
func (i *ImageWrapper) Resize(maxBytes int) error
Resize returns a new ImageWrapper with the original image converted to jpeg and reduces quality until the image is under maxBytes.
type Response ¶
type Response struct {
Title string `json:"title"`
Date string `json:"date"`
URL string `json:"url"`
HdURL string `json:"hdurl"`
MediaType string `json:"media_type"`
Explanation string `json:"explanation"`
Thumbnail string `json:"thumbnail_url"`
Copyright string `json:"copyright"`
Service string `json:"service_version"`
}
Response is a single JSON response from the APOD API.
func (*Response) CreateExplanation ¶
CreateExplanation creates a markdown formatted explanation of today's APOD
func (*Response) DownloadRawImage ¶
func (a *Response) DownloadRawImage() (*ImageWrapper, error)
DownloadRawImage downloads the image without resizing