-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountries.go
More file actions
44 lines (38 loc) · 1.21 KB
/
countries.go
File metadata and controls
44 lines (38 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package holidays
import (
"context"
"fmt"
"net/url"
)
// Subdivision represents a region or administrative subdivision of a country.
type Subdivision struct {
Code string `json:"code"`
Name string `json:"name"`
}
// Country represents a supported country.
type Country struct {
Name string `json:"name"`
Alpha2 string `json:"alpha2"`
Subdivisions []Subdivision `json:"subdivisions,omitempty"`
}
// Countries returns all supported countries.
func (c *Client) Countries(ctx context.Context) ([]Country, error) {
var result []Country
if err := c.get(ctx, "/countries", url.Values{}, &result); err != nil {
return nil, err
}
return result, nil
}
// Country returns details for a single country identified by its ISO 3166
// alpha-2 code (e.g. "US"). The response includes available subdivision codes
// that can be used as region filters in Holidays().
func (c *Client) Country(ctx context.Context, countryCode string) (*Country, error) {
if countryCode == "" {
return nil, fmt.Errorf("holidays: Country: countryCode must not be empty")
}
var result Country
if err := c.get(ctx, "/country/"+countryCode, url.Values{}, &result); err != nil {
return nil, err
}
return &result, nil
}