-
Notifications
You must be signed in to change notification settings - Fork 0
/
gogoose.go
65 lines (52 loc) · 1.24 KB
/
gogoose.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
package gogoose
import (
"bytes"
"encoding/json"
"net/http"
)
type GooseClient struct {
Url string
}
func New(localHostUrl string) *GooseClient {
return &GooseClient{Url: localHostUrl}
}
func (gc *GooseClient) All() (*http.Response, error) {
resp, err := http.Get(gc.Url + "all")
if err != nil {
return nil, err
}
return resp, nil
}
func (gc *GooseClient) Send(jsonData interface{}) (*http.Response, error) {
jsonBytes, err := json.Marshal(jsonData)
if err != nil {
return nil, err
}
resp, err := http.Post(gc.Url+"send", "application/json", bytes.NewBuffer(jsonBytes))
if err != nil {
return nil, err
}
return resp, nil
}
func (gc *GooseClient) Update(jsonData interface{}) (*http.Response, error) {
jsonBytes, err := json.Marshal(jsonData)
if err != nil {
return nil, err
}
resp, err := http.Post(gc.Url+"update", "application/json", bytes.NewBuffer(jsonBytes))
if err != nil {
return nil, err
}
return resp, nil
}
func (gc *GooseClient) Delete(jsonData interface{}) (*http.Response, error) {
jsonBytes, err := json.Marshal(jsonData)
if err != nil {
return nil, err
}
resp, err := http.Post(gc.Url+"delete", "application/json", bytes.NewBuffer(jsonBytes))
if err != nil {
return nil, err
}
return resp, nil
}