-
Notifications
You must be signed in to change notification settings - Fork 35
/
client.go
67 lines (56 loc) · 1.39 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 rest
import "net/http"
// Client is the interface of a rest client that can build requests for the
// different http verbs.
type Client interface {
Verb(verb string) *Request
Post() *Request
Get() *Request
Put() *Request
Delete() *Request
}
type ClientConfig struct {
APIBaseURL string
Verb string
TokenURL string
ZAAID string
MSP bool
}
// HTTPClient is the interface of an http client that is compatible with
// *http.Client.
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
type client struct {
config ClientConfig
httpClient HTTPClient
}
// New Client creates a new REST Client.
func NewClient(httpClient HTTPClient, clientConfig ClientConfig) Client {
return &client{
config: clientConfig,
httpClient: httpClient,
}
}
// Verb creates a new *Request with given HTTP verb, e.g. 'POST', 'PUT', 'GET'
// or 'DELETE'.
func (c *client) Verb(verb string) *Request {
c.config.Verb = verb
return NewRequest(c.httpClient, c.config)
}
// Get creates a new HTTP GET request.
func (c *client) Get() *Request {
return c.Verb("GET")
}
// Post creates a new HTTP POST request.
func (c *client) Post() *Request {
return c.Verb("POST")
}
// Put creates a new HTTP PUT request.
func (c *client) Put() *Request {
return c.Verb("PUT")
}
// Delete creates a new HTTP DELETE request.
func (c *client) Delete() *Request {
return c.Verb("DELETE")
}