-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeo.go
50 lines (39 loc) · 1.01 KB
/
geo.go
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
45
46
47
48
49
50
package ebird
import (
"context"
"fmt"
"net/url"
)
type AdjacentRegion struct {
Code string `json:"code,omitempty"`
Name string `json:"name,omitempty"`
}
type AdjacentRegionsOptions struct {
fmt string
}
type AdjacentRegionsOption func(*AdjacentRegionsOptions)
func WithFormat(format string) AdjacentRegionsOption {
return func(o *AdjacentRegionsOptions) {
o.fmt = format
}
}
func (c *Client) AdjacentRegions(ctx context.Context, regionCode string, opts ...AdjacentRegionsOption) ([]AdjacentRegion, error) {
if regionCode == "" {
return nil, fmt.Errorf("regionCode cannot be empty")
}
options := &AdjacentRegionsOptions{}
for _, opt := range opts {
opt(options)
}
params := url.Values{}
if options.fmt != "" {
params.Set("fmt", options.fmt)
}
endpoint := fmt.Sprintf(APIEndpoints.AdjacentRegions, regionCode)
var regions []AdjacentRegion
err := c.get(ctx, endpoint, params, ®ions)
if err != nil {
return nil, fmt.Errorf("failed to get adjacent regions: %w", err)
}
return regions, nil
}