-
Notifications
You must be signed in to change notification settings - Fork 4
/
govalent.go
47 lines (39 loc) · 1.18 KB
/
govalent.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 govalent provides the binding for Covalent Rest APIs.
package govalent
import (
"github.com/AlchemistsLab/govalent/class_a"
"github.com/AlchemistsLab/govalent/class_b"
"github.com/AlchemistsLab/govalent/client"
"net/http"
"time"
)
//constant used for API client
const (
APIURL = "https://api.covalenthq.com/v1/"
defaultHTTPTimeout = 80 * time.Second
)
//Default HTTP client
var httpClient = &http.Client{Timeout: defaultHTTPTimeout}
// APIKey is Covalent API Key.
var APIKey string
// ClassA uses endpoint without client.
func ClassA() *class_a.Client {
api := client.New(APIURL, APIKey, httpClient)
return &class_a.Client{API: *api}
}
// ClassB uses endpoint without client.
func ClassB() *class_b.Client {
api := client.New(APIURL, APIKey, httpClient)
return &class_b.Client{API: *api}
}
//Client is the Covalent client. It contains all resources available.
type Client struct {
ClassA class_a.Client
ClassB class_b.Client
}
//Init initializes the covalent client with given API key, secret key.
func (c *Client) Init(apiKey string) {
api := client.New(APIURL, apiKey, httpClient)
c.ClassA = class_a.Client{API: *api}
c.ClassB = class_b.Client{API: *api}
}