-
Notifications
You must be signed in to change notification settings - Fork 11
/
client.go
36 lines (31 loc) · 871 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
// Package cloudhealth is a wrapper for the CloudHealth API.
package cloudhealth
import (
"errors"
"net/url"
)
var defaultTimeout int = 15
// Client communicates with the CloudHealth API.
type Client struct {
ApiKey string
EndpointURL *url.URL
Timeout int
}
// ErrClientAuthenticationError is returned for authentication errors with the API.
var ErrClientAuthenticationError = errors.New("Authentication Error with CloudHealth")
// NewClient returns a new cloudhealth.Client for accessing the CloudHealth API.
func NewClient(apiKey string, defaultEndpointURL string, timeout ...int) (*Client, error) {
s := &Client{
ApiKey: apiKey,
}
endpointURL, err := url.Parse(defaultEndpointURL)
if err != nil {
return nil, err
}
s.EndpointURL = endpointURL
s.Timeout = defaultTimeout
if len(timeout) > 0 {
s.Timeout = timeout[0]
}
return s, nil
}