forked from mhelmetag/surflinef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
42 lines (32 loc) · 771 Bytes
/
client.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
package surflinef
import (
"net/http"
"net/url"
)
// Client is the SurflineF HTTP Client.
type Client struct {
BaseURL *url.URL
httpClient *http.Client
}
// DefaultClient returns a default configured SurflineF Client.
func DefaultClient() (*Client, error) {
u, err := url.Parse("http://api.surfline.com/v1/forecasts")
if err != nil {
return nil, err
}
httpClient := http.DefaultClient
client := Client{BaseURL: u, httpClient: httpClient}
return &client, err
}
func (c *Client) get(u *url.URL) (*http.Response, error) {
req, err := http.NewRequest("GET", u.String(), nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", "application/json")
resp, err := c.httpClient.Do(req)
if err != nil {
return nil, err
}
return resp, err
}