nagerdate

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 nagerdate is the library behind the nagerdate command line: the HTTP client, request shaping, and the typed data models for the Nager.Date public holiday API (date.nager.at).

No API key or authentication is required. The API provides public holiday data for 123 countries.

Index

Constants

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

DefaultUserAgent identifies the client to the server.

View Source
const Host = "date.nager.at"

Host is the site this client talks to.

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 the Nager.Date API over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig builds a Client from an explicit Config.

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) GetCountries

func (c *Client) GetCountries(ctx context.Context) ([]Country, error)

GetCountries returns all available countries supported by the API.

func (*Client) GetHolidays

func (c *Client) GetHolidays(ctx context.Context, year int, countryCode string) ([]Holiday, error)

GetHolidays fetches public holidays for the given country and year.

func (*Client) GetLongWeekends

func (c *Client) GetLongWeekends(ctx context.Context, year int, countryCode string) ([]LongWeekend, error)

GetLongWeekends fetches long weekends for the given country and year.

func (*Client) GetNextWorldwide

func (c *Client) GetNextWorldwide(ctx context.Context) ([]Holiday, error)

GetNextWorldwide fetches the next public holidays worldwide.

type Config

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

Config holds all tunable parameters for the Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults for the Nager.Date API.

type Country

type Country struct {
	CountryCode string `kit:"id" json:"country_code"`
	Name        string `json:"name"`
}

Country is one supported country.

type Domain

type Domain struct{}

Domain is the nagerdate driver.

func (Domain) Classify

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

Classify turns an input 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 Holiday

type Holiday struct {
	Date        string   `kit:"id" json:"date"`
	LocalName   string   `json:"local_name"`
	Name        string   `json:"name"`
	CountryCode string   `json:"country_code"`
	Fixed       bool     `json:"fixed"`
	Global      bool     `json:"global"`
	Counties    []string `json:"counties"`
	Types       []string `json:"types"`
}

Holiday is one public holiday record.

type LongWeekend

type LongWeekend struct {
	StartDate     string `kit:"id" json:"start_date"`
	EndDate       string `json:"end_date"`
	DayCount      int    `json:"day_count"`
	NeedBridgeDay bool   `json:"need_bridge_day"`
}

LongWeekend is one long weekend record.

Jump to

Keyboard shortcuts

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