sunrisesunset

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "sunrise-sunset-cli/dev (+https://github.com/tamnd/sunrise-sunset-cli)"

DefaultUserAgent identifies the client to the API.

View Source
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.

func (*Client) Get

func (c *Client) Get(ctx context.Context, url string) ([]byte, error)

Get fetches url and returns the response body. It paces and retries according to the client's settings.

func (*Client) GetSolar

func (c *Client) GetSolar(ctx context.Context, lat, lng float64, date string) (*SolarInfo, error)

GetSolar fetches solar data for the given coordinates and optional date. Pass an empty date string to get today's data in UTC.

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

func (Domain) Classify(input string) (uriType, id string, err error)

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.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL