-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnamesilo.go
60 lines (49 loc) · 1.19 KB
/
namesilo.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
// Package namesilo A Go client library for accessing the Namesilo API.
package namesilo
import (
"fmt"
"net/http"
"net/url"
querystring "github.com/google/go-querystring/query"
)
const (
// DefaultAPIEndpoint The default API endpoint.
DefaultAPIEndpoint = "https://www.namesilo.com/api"
// SandboxAPIEndpoint The sandbox API endpoint.
SandboxAPIEndpoint = "https://sandbox.namesilo.com/api"
)
// Response Codes.
const (
SuccessfulAPIOperation = "300"
SuccessfulRegistration = "301"
SuccessfulOrder = "302"
)
// Client the Namesilo client.
type Client struct {
Endpoint string
HTTPClient *http.Client
}
// NewClient Creates a Namesilo client.
func NewClient(httpClient *http.Client) *Client {
if httpClient == nil {
httpClient = http.DefaultClient
}
return &Client{
Endpoint: DefaultAPIEndpoint,
HTTPClient: httpClient,
}
}
func (c *Client) get(name string, params interface{}) (*http.Response, error) {
uri, err := url.Parse(fmt.Sprintf("%s/%s", c.Endpoint, name))
if err != nil {
return nil, err
}
if params != nil {
v, err := querystring.Values(params)
if err != nil {
return nil, err
}
uri.RawQuery = v.Encode()
}
return c.HTTPClient.Get(uri.String())
}