-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient.go
67 lines (55 loc) · 1.34 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
package labstack
import (
"github.com/go-resty/resty/v2"
)
type (
Client struct {
key string
resty *resty.Client
}
Error struct {
StatusCode int `json:"status_code"`
Code int `json:"code"`
Message string `json:"message"`
}
)
const (
url = "https://api.labstack.com"
)
func NewClient(key string) *Client {
return &Client{
key: key,
resty: resty.New().SetHostURL(url).SetAuthToken(key),
}
}
func (c *Client) Currency() *CurrencyService {
return &CurrencyService{
resty: resty.New().SetHostURL("https://currency.labstack.com/api/v1").SetAuthToken(c.key),
}
}
func (c *Client) Domain() *DomainService {
return &DomainService{
resty: resty.New().SetHostURL("https://domain.labstack.com/api/v1").SetAuthToken(c.key),
}
}
func (c *Client) Email() *EmailService {
return &EmailService{
resty: resty.New().SetHostURL("https://email.labstack.com/api/v1").SetAuthToken(c.key),
}
}
func (c *Client) IP() *IPService {
return &IPService{
resty: resty.New().SetHostURL("https://ip.labstack.com/api/v1").SetAuthToken(c.key),
}
}
func (c *Client) Webpage() *WebpageService {
return &WebpageService{
resty: resty.New().SetHostURL("https://webpage.labstack.com/api/v1").SetAuthToken(c.key),
}
}
func isError(status int) bool {
return status < 200 || status >= 300
}
func (e *Error) Error() string {
return e.Message
}