-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.go
50 lines (40 loc) · 901 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
package mysqlrouter
import (
"errors"
"net/http"
)
const apiVer = "20190715"
// Client holds the configuration for 20190715 version API client.
type Client struct {
URL string
Username string
Password string
Options *Options
}
type Options struct {
Transport *http.Transport
}
func newClient(url, user, pass string, Options *Options) *Client {
return &Client{
URL: url + "/api/" + apiVer,
Username: user,
Password: pass,
Options: Options,
}
}
// New creates a new API client.
func New(url, user, pass string, Options *Options) (*Client, error) {
if url == "" {
return nil, errors.New(errEmptyClientInformation)
}
client := newClient(url, user, pass, Options)
err := client.verifyConnection()
if err != nil {
return nil, err
}
return client, nil
}
func (c *Client) verifyConnection() error {
_, err := c.request(c.URL + "/swagger.json")
return err
}