Documentation
¶
Overview ¶
Package sunrisesunset is the library behind the sunrise-sunset command line: the HTTP client, request shaping, and the typed data models for api.sunrise-sunset.org.
The Client is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public site throws under load.
Index ¶
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "sunrise-sunset-cli/dev (+https://github.com/tamnd/sunrise-sunset-cli)"
DefaultUserAgent identifies the client to the API.
const Host = "api.sunrise-sunset.org"
Host is the API hostname.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to api.sunrise-sunset.org over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 200ms minimum gap between requests, and five retries on transient errors.
type Domain ¶
type Domain struct{}
Domain is the sunrise-sunset driver. It carries no state; the per-run client is built by the factory Register hands kit.
func (Domain) Classify ¶
Classify turns an input string into a (type, id) pair. "lat,lon" or a bare coordinate pair maps to ("point", input). "YYYY-MM-DD" maps to ("date", input).
func (Domain) Info ¶
func (Domain) Info() kit.DomainInfo
Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.
type SolarInfo ¶
type SolarInfo struct {
ID string `kit:"id" json:"id"`
Latitude float64 `json:"latitude"`
Longitude float64 `json:"longitude"`
Date string `json:"date"`
Sunrise string `json:"sunrise"`
Sunset string `json:"sunset"`
SolarNoon string `json:"solar_noon"`
DayLength string `json:"day_length"`
CivilTwilightBegin string `json:"civil_twilight_begin"`
CivilTwilightEnd string `json:"civil_twilight_end"`
NauticalTwilightBegin string `json:"nautical_twilight_begin"`
NauticalTwilightEnd string `json:"nautical_twilight_end"`
AstroTwilightBegin string `json:"astro_twilight_begin"`
AstroTwilightEnd string `json:"astro_twilight_end"`
Timezone string `json:"timezone"`
}
SolarInfo holds the sunrise/sunset data for a given location and date.