forked from cloudhut/connect-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
56 lines (47 loc) · 1012 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
48
49
50
51
52
53
54
55
56
package connect
import (
"crypto/tls"
"github.com/go-resty/resty/v2"
"time"
)
// Client that talks to the Kafka Connect instances via HTTP
type Client struct {
client *resty.Client
// General config
hostURL string
userAgent string
timeout time.Duration
// Security
//
// Basic auth
username string
password string
// Bearer token
authToken string
// TLS
tlsCfg *tls.Config
}
func NewClient(opts ...ClientOption) *Client {
c := &Client{
client: nil,
hostURL: "",
userAgent: "CloudHut-Connect-Client",
timeout: 60 * time.Second,
tlsCfg: &tls.Config{},
}
for _, opt := range opts {
opt(c)
}
c.client = resty.New().
SetHostURL(c.hostURL).
SetHeader("User-Agent", c.userAgent).
SetHeader("Accept", "application/json").
SetHeader("Content-Type", "application/json").
SetTimeout(c.timeout).
SetError(&ApiError{}).
SetBasicAuth(c.username, c.password).
SetAuthToken(c.authToken).
SetDisableWarn(true).
SetTLSClientConfig(c.tlsCfg)
return c
}