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: 9 Imported by: 0

Documentation

Overview

Package sunrisesunset is the library behind the sunrisesunset command line: the HTTP client, request shaping, and the typed data models for the Sunrise-Sunset API (https://api.sunrise-sunset.org).

The Client paces and retries requests to stay polite. Build your endpoint calls and JSON decoding on top of it.

Index

Constants

View Source
const Host = "api.sunrise-sunset.org"

Host is the API host this client talks to.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the Sunrise-Sunset API over HTTP.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured from cfg.

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, lat, lng, date string) (*SunTimes, error)

Lookup fetches sunrise/sunset times for the given coordinates and date. lat and lng are decimal degree strings (e.g. "40.7128", "-74.0060"). date is "YYYY-MM-DD" or "today".

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds all tuneable parameters for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the production configuration for api.sunrise-sunset.org.

type Domain

type Domain struct{}

Domain is the sunrisesunset driver.

func (Domain) Classify

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

Classify turns a coordinate pair into the canonical (type, id).

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 SunTimes

type SunTimes struct {
	Lat                string `kit:"id" json:"lat" table:"lat"`
	Lng                string `json:"lng" table:"lng"`
	Date               string `json:"date" table:"date"`
	Sunrise            string `json:"sunrise" table:"sunrise"`
	Sunset             string `json:"sunset" table:"sunset"`
	SolarNoon          string `json:"solar_noon" table:"solar_noon"`
	DayLengthHours     string `json:"day_length_hours" table:"day_length_hours"`
	CivilTwilightBegin string `json:"civil_twilight_begin" table:"civil_twilight_begin"`
	CivilTwilightEnd   string `json:"civil_twilight_end" table:"civil_twilight_end"`
}

SunTimes is one record: the solar event times for a given location and date.

Jump to

Keyboard shortcuts

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