-
Notifications
You must be signed in to change notification settings - Fork 0
/
cml.go
50 lines (45 loc) · 1.05 KB
/
cml.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 cmlclient
import (
"crypto/tls"
"net/http"
"sync"
"time"
)
type apiClient interface {
Do(req *http.Request) (*http.Response, error)
}
type Client struct {
host string
apiToken string
userpass userPass
httpClient apiClient
compatibilityErr error
state *apiClientState
mu sync.RWMutex
labCache map[string]*Lab
useCache bool
version string
}
// New returns a new CML client instance. The host must be a valid URL including
// scheme (https://).
func New(host string, insecure, useCache bool) *Client {
tr := http.DefaultTransport.(*http.Transport)
tr.TLSClientConfig = &tls.Config{
InsecureSkipVerify: insecure,
}
tr.Proxy = http.ProxyFromEnvironment
return &Client{
host: host,
apiToken: "",
version: "",
userpass: userPass{},
httpClient: &http.Client{
Timeout: 15 * time.Second,
Transport: tr,
},
compatibilityErr: nil,
state: newState(),
labCache: make(map[string]*Lab),
useCache: useCache,
}
}