Skip to content

Commit 1eecee3

Browse files
Update Go examples integration
- Add VERTEX_LABEL environment variable - Use configurable vertex labels in examples - Update root-level connection labels
1 parent cc23a30 commit 1eecee3

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

glv-examples/gremlin-go/connections.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ func withRemote() {
4646
// Creating the graph traversal
4747
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
4848

49-
// Drop existing vertices
50-
prom := g.V().Drop().Iterate()
51-
<-prom
52-
5349
// Simple query to verify connection
54-
g.AddV().Iterate()
55-
count, _ := g.V().Count().Next()
50+
g.AddV("connection").Iterate()
51+
count, _ := g.V().HasLabel("connection").Count().Next()
5652
fmt.Println("Vertex count:", *count)
5753
}
5854

@@ -75,7 +71,7 @@ func withConfigs() {
7571
defer driverRemoteConnection.Close()
7672
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
7773

78-
g.AddV().Iterate()
79-
count, _ := g.V().Count().Next()
74+
g.AddV("connection").Iterate()
75+
count, _ := g.V().HasLabel("connection").Count().Next()
8076
fmt.Println("Vertex count:", *count)
8177
}

gremlin-go/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ services:
6060
- RUN_BASIC_AUTH_INTEGRATION_TESTS=true
6161
- GREMLIN_SOCKET_SERVER_URL=ws://gremlin-socket-server-go
6262
- GREMLIN_SOCKET_SERVER_CONFIG_PATH=/go_app/gremlin-socket-server/conf/test-ws-gremlin.yaml
63+
- VERTEX_LABEL=go-example
6364
working_dir: /go_app
6465
command: >
6566
bash -c "go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest

gremlin-go/examples/basic_gremlin.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func getEnvOrDefaultString(key string, defaultValue string) string {
3636

3737
func main() {
3838
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
39+
vertexLabel := getEnvOrDefaultString("VERTEX_LABEL", "person")
3940
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
4041
if err != nil {
4142
fmt.Println(err)
@@ -45,9 +46,9 @@ func main() {
4546
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
4647

4748
// Basic Gremlin: adding and retrieving data
48-
v1, err := g.AddV("person-go-ex").Property("name", "marko").Next()
49-
v2, err := g.AddV("person-go-ex").Property("name", "stephen").Next()
50-
v3, err := g.AddV("person-go-ex").Property("name", "vadas").Next()
49+
v1, err := g.AddV(vertexLabel).Property("name", "marko").Next()
50+
v2, err := g.AddV(vertexLabel).Property("name", "stephen").Next()
51+
v3, err := g.AddV(vertexLabel).Property("name", "vadas").Next()
5152
v1Vertex, err := v1.GetVertex()
5253
v2Vertex, err := v2.GetVertex()
5354
v3Vertex, err := v3.GetVertex()
@@ -68,17 +69,17 @@ func main() {
6869
}
6970

7071
// Retrieve the data from the "marko" vertex
71-
marko, err := g.V().Has("person-go-ex", "name", "marko").Values("name").Next()
72+
marko, err := g.V().Has(vertexLabel, "name", "marko").Values("name").Next()
7273
fmt.Println("name:", marko.GetString())
7374

7475
// Find the "marko" vertex and then traverse to the people he "knows" and return their data
75-
peopleMarkoKnows, err := g.V().Has("person-go-ex", "name", "marko").Out("knows").Values("name").ToList()
76+
peopleMarkoKnows, err := g.V().Has(vertexLabel, "name", "marko").Out("knows").Values("name").ToList()
7677
for _, person := range peopleMarkoKnows {
7778
fmt.Println("marko knows", person.GetString())
7879
}
7980

8081
// clean added data
81-
promise = g.V().HasLabel("person-go-ex").Drop().Iterate()
82+
promise = g.V().HasLabel(vertexLabel).Drop().Iterate()
8283
err = <-promise
8384
if err != nil {
8485
fmt.Println(err)

gremlin-go/examples/connections.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func main() {
4141

4242
func withRemote() {
4343
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
44+
vertexLabel := getEnvOrDefaultString("VERTEX_LABEL", "connection")
4445

4546
// Creating the connection to the server
4647
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
@@ -58,16 +59,17 @@ func withRemote() {
5859
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
5960

6061
// Simple query to verify connection
61-
g.AddV("go-conn-ex").Iterate()
62+
g.AddV(vertexLabel).Iterate()
6263
count, _ := g.V().Count().Next()
6364
fmt.Println("Vertex count:", *count)
6465

6566
// clean added data
66-
g.V().HasLabel("go-conn-ex").Drop().Iterate()
67+
g.V().HasLabel(vertexLabel).Drop().Iterate()
6768
}
6869

6970
func withConfigs() {
7071
serverURL := getEnvOrDefaultString("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
72+
vertexLabel := getEnvOrDefaultString("VERTEX_LABEL", "connection")
7173

7274
// Connecting to the server with customized configurations
7375
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL,
@@ -87,10 +89,10 @@ func withConfigs() {
8789
defer driverRemoteConnection.Close()
8890
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)
8991

90-
g.AddV("go-conn-ex").Iterate()
92+
g.AddV(vertexLabel).Iterate()
9193
count, _ := g.V().Count().Next()
9294
fmt.Println("Vertex count:", *count)
9395

9496
// clean added data
95-
g.V().HasLabel("go-conn-ex").Drop().Iterate()
97+
g.V().HasLabel(vertexLabel).Drop().Iterate()
9698
}

0 commit comments

Comments
 (0)