forked from iopipe/turtle-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject.go
54 lines (46 loc) · 1009 Bytes
/
object.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
package main
import (
"log"
"strings"
"io/ioutil"
"net/http"
"net/url"
)
/*******************************************************
Object Mapper
*******************************************************/
type objectInterface struct {
ClassID string `json:"classid"`
Properties map[string]interface{} `json:"properties"`
}
type Object struct {
path *url.URL
}
func (object *Object) read() string {
path := object.path.String()
object.path.String()
res, err := http.Get(path)
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
res.Body.Close()
return string(body[:])
}
func (object *Object) update(content string) string {
path := object.path.String()
reader := strings.NewReader(content)
res, err := http.Post(path, "application/json", reader)
defer res.Body.Close()
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
return string(body[:])
}