forked from DanielHeckrath/pushd-client-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequest.go
61 lines (49 loc) · 1.12 KB
/
request.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
package client
import (
"io"
"io/ioutil"
"net/http"
)
func (this *Request) get(path string) (int, string, error) {
url := this.endpoint + path
res, err := this.client.Get(url)
if err != nil {
return 0, "", err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return 0, "", err
}
return res.StatusCode, string(body), nil
}
func (this *Request) post(path, contentType string, payload io.Reader) (int, string, error) {
url := this.endpoint + path
res, err := this.client.Post(url, contentType, payload)
if err != nil {
return 0, "", err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return 0, "", err
}
return res.StatusCode, string(body), nil
}
func (this *Request) del(path string) (int, string, error) {
url := this.endpoint + path
req, err := http.NewRequest("DELETE", url, nil)
if err != nil {
return 0, "", err
}
res, err := this.client.Do(req)
if err != nil {
return 0, "", err
}
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
return 0, "", err
}
return res.StatusCode, string(body), nil
}