-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.go
48 lines (39 loc) · 986 Bytes
/
index.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
package neo4j
import (
"errors"
"fmt"
)
// Index struct
type Index struct {
Name string
Config map[string]interface{}
}
// CreateNodeIndex func
func (neo4j *Neo4j) CreateNodeIndex(index *Index) error {
return neo4j.CreateIndex(index)
}
// CreateIndex is here for backward compatibility
func (neo4j *Neo4j) CreateIndex(index *Index) error {
if index.Name == "" {
return errors.New("Name must be set!")
}
postData := ""
if len(index.Config) > 0 {
config, err := jsonEncode(index.Config)
if err != nil {
return err
}
postData = fmt.Sprintf(`{"name" : "%s", "config" : %s }`, index.Name, config)
} else {
postData = fmt.Sprintf(`{"name" : "%s" }`, index.Name)
}
_, err := neo4j.doRequest("POST", neo4j.IndexNodeURL, postData)
return err
}
// DeleteIndex func
func (neo4j *Neo4j) DeleteIndex(name string) error {
url := neo4j.IndexNodeURL + "/" + name
//if node not found Neo4j returns 404
_, err := neo4j.doRequest("DELETE", url, "")
return err
}