-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
103 lines (83 loc) · 2.47 KB
/
main.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 main
import (
"fmt"
gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver"
)
// syntactic sugar
var __ = gremlingo.T__
var gt = gremlingo.P.Gt
var order = gremlingo.Order
type FileSystem struct {
driverRemoteConnection gremlingo.DriverRemoteConnection
g *gremlingo.GraphTraversalSource
}
type Bookmark struct {
path, name string
}
func NewFileSystem(connectionString string) (*FileSystem, error) {
// Creating the connection to the server.
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(connectionString)
if err != nil {
return nil, err
}
// Creating graph traversal
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
fs := &FileSystem{driverRemoteConnection: *driverRemoteConnection, g: g}
return fs, nil
}
func (fs *FileSystem) addBookmark(b Bookmark) <-chan error {
promise := fs.g.AddV("bookmark").Property("path", b.path).Property("name", b.name).Iterate()
return promise
}
// FIX: Rise errors to stop upper level executions if something wasn't added.
func (fs *FileSystem) addBookmarks(bookmarks []Bookmark) {
for _, bookmark := range bookmarks {
// Wait for all steps to finish execution and check for error.
promiseErr := <-fs.addBookmark(bookmark)
if promiseErr != nil {
fmt.Println(promiseErr)
return
}
}
}
// Perform traversal
func (fs *FileSystem) getBookmarks() []*gremlingo.Result {
result, err := fs.g.V().HasLabel("bookmark").Values("path").ToList()
if result == nil {
return nil
}
if err != nil {
fmt.Println(err)
return nil
}
return result
}
func (fs *FileSystem) getBookmarksByName(name string) []*gremlingo.Result {
result, err := fs.g.V().HasLabel("bookmark").Has("name", name).Values("path").ToList()
if result == nil {
return nil
}
if err != nil {
fmt.Println(err)
return nil
}
return result
}
func main() {
fs, err := NewFileSystem("ws://localhost:8182/gremlin")
if err != nil {
fmt.Println(err)
return
}
// fs.addBookmarks([]Bookmark{
// { name: "FileSystem", path: "S:\\ds13\\Projects\\--personal\\KnowledgeBase\\FileSystem\\" },
// { name: "Bomonka", path: "E:\\Projects\\--educational\\Bomonka\\" },
// { name: "Configs", path: "E:\\Scripts\\" },
// })
vertices := fs.getBookmarksByName("Bomonka")
for _, v := range vertices {
fmt.Println(v.GetString())
}
// Cleanup
defer fs.driverRemoteConnection.Close()
}