-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
47 lines (36 loc) · 812 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
43
44
45
46
47
package climacell
import (
"net/http"
"time"
)
// BaseURL is the base url of the climacell API
var BaseURL string
func init() {
BaseURL = "https://api.climacell.co/v3"
}
// Client represents the climacell API client
type Client struct {
httpClient *http.Client
baseURL string
apiKey string
}
// NewClient returns a new climacell Client and checks for the
// validity of the provided baseURL
func NewClient(apiKey string, httpClient *http.Client) (*Client, error) {
client := &Client{}
if BaseURL == "" {
return nil, ErrInvalidBaseURL
}
if apiKey == "" {
return nil, ErrInvalidAPIKey
}
client.baseURL = BaseURL
client.apiKey = apiKey
if httpClient == nil {
httpClient = &http.Client{
Timeout: 15 * time.Second,
}
}
client.httpClient = httpClient
return client, nil
}