-
Notifications
You must be signed in to change notification settings - Fork 0
/
neo4go.go
103 lines (91 loc) · 3.2 KB
/
neo4go.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package neo4go
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
)
type Error struct {
Message string
Exception string
Stackstrace []string
}
func (e Error) Error() string {
return fmt.Sprintf("%s: %s", e.Message, e.Exception)
}
type Neo4j struct {
URL string
}
type Node struct {
Id uint
Relationships string
RelationshipsOut string `json:"outgoing_relationships"`
RelationshipsIn string `json:"incoming_relationships"`
RelationshipsAll string `json:"all_relationships"`
RelationshipsCreate string `json:"create_relationship"`
Data map[string]interface{}
Traverse string
Property string
Properties string
Self string
Extensions map[string]interface{}
Start string // relationships & traverse // returns both obj & string
End string // relationships & traverse // returns both obj & string
Type string // relationships & traverse
Indexed string // index related
Length string // traverse framework
}
/*
{
"outgoing_relationships" : "http://localhost:7474/db/data/node/0/relationships/out",
"data" : {
"name" : "foobar"
},
"traverse" : "http://localhost:7474/db/data/node/0/traverse/{returnType}",
"all_typed_relationships" : "http://localhost:7474/db/data/node/0/relationships/all/{-list|&|types}",
"self" : "http://localhost:7474/db/data/node/0",
"property" : "http://localhost:7474/db/data/node/0/properties/{key}",
"properties" : "http://localhost:7474/db/data/node/0/properties",
"outgoing_typed_relationships" : "http://localhost:7474/db/data/node/0/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://localhost:7474/db/data/node/0/relationships/in",
"extensions" : {
},
"create_relationship" : "http://localhost:7474/db/data/node/0/relationships",
"paged_traverse" : "http://localhost:7474/db/data/node/0/paged/traverse/{returnType}{?pageSize,leaseTime}",
"all_relationships" : "http://localhost:7474/db/data/node/0/relationships/all",
"incoming_typed_relationships" : "http://localhost:7474/db/data/node/0/relationships/in/{-list|&|types}"
}
*/
type Property map[string]string
func NewNeo4j(uri string) (*Neo4j, error) {
neo := new(Neo4j)
neo.URL = uri
return neo, nil
}
func (neo *Neo4j) GetNode(id uint) (*Node, error) {
url := neo.URL + "/db/data/node/%d"
url = fmt.Sprintf(url, id)
resp, err := http.Get(url)
if err != nil {
return nil, err
}
// Read all data from response
body, _ := ioutil.ReadAll(resp.Body)
node := new(Node)
if resp.StatusCode == 200 {
err = json.Unmarshal(body, node)
node.Id = id
return node, err
} else {
err := new(Error)
_ = json.Unmarshal(body, err)
log.Printf("%s\n", string(body))
}
return node, err
}
// CreateNode creates a new node and returns it
func (neo *Neo4j) CreateNode(data map[string]string) (*Node, error) {
_, err := json.Marshal(data)
//node := new(Node)
if err != nil {
return nil, errors.New("Unable to Marshal Json data")
}
return nil, nil
}