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
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetCountries(ctx context.Context) ([]Country, error)
- func (c *Client) GetHolidays(ctx context.Context, year int, countryCode string) ([]Holiday, error)
- func (c *Client) GetLongWeekends(ctx context.Context, year int, countryCode string) ([]LongWeekend, error)
- func (c *Client) GetNextWorldwide(ctx context.Context) ([]Holiday, error)
- type Config
- type Country
- type Domain
- type Holiday
- type LongWeekend
Constants ¶
const DefaultUserAgent = "nagerdate/dev (+https://github.com/tamnd/nagerdate-cli)"
DefaultUserAgent identifies the client to the server.
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 NewClientFromConfig ¶
NewClientFromConfig builds a Client from an explicit Config.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings.
func (*Client) GetCountries ¶
GetCountries returns all available countries supported by the API.
func (*Client) GetHolidays ¶
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.
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 Domain ¶
type Domain struct{}
Domain is the nagerdate driver.
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 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.