Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions glv-examples/gremlin-go/basic_gremlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ import (
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

var serverURL = "ws://localhost:8182/gremlin"
var vertexLabel = "person"

func main() {
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
if err != nil {
fmt.Println(err)
return
Expand All @@ -35,9 +38,9 @@ func main() {
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

// Basic Gremlin: adding and retrieving data
v1, err := g.AddV("person").Property("name", "marko").Next()
v2, err := g.AddV("person").Property("name", "stephen").Next()
v3, err := g.AddV("person").Property("name", "vadas").Next()
v1, err := g.AddV(vertexLabel).Property("name", "marko").Next()
v2, err := g.AddV(vertexLabel).Property("name", "stephen").Next()
v3, err := g.AddV(vertexLabel).Property("name", "vadas").Next()
v1Vertex, err := v1.GetVertex()
v2Vertex, err := v2.GetVertex()
v3Vertex, err := v3.GetVertex()
Expand All @@ -58,11 +61,11 @@ func main() {
}

// Retrieve the data from the "marko" vertex
marko, err := g.V().Has("person", "name", "marko").Values("name").Next()
marko, err := g.V().Has(vertexLabel, "name", "marko").Values("name").Next()
fmt.Println("name:", marko.GetString())

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
peopleMarkoKnows, err := g.V().Has("person", "name", "marko").Out("knows").Values("name").ToList()
peopleMarkoKnows, err := g.V().Has(vertexLabel, "name", "marko").Out("knows").Values("name").ToList()
for _, person := range peopleMarkoKnows {
fmt.Println("marko knows", person.GetString())
}
Expand Down
31 changes: 15 additions & 16 deletions glv-examples/gremlin-go/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ import (
"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

var serverURL = "ws://localhost:8182/gremlin"
var vertexLabel = "connection"

func main() {
withRemote()
withConfigs()
}

func withRemote() {
// Creating the connection to the server
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
// Creating the connection to the server
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)

// Error handling
if err != nil {
Expand All @@ -43,22 +46,18 @@ func withRemote() {
// Cleanup
defer driverRemoteConnection.Close()

// Creating the graph traversal
// Creating the graph traversal
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

// Drop existing vertices
prom := g.V().Drop().Iterate()
<-prom

// Simple query to verify connection
g.AddV().Iterate()
count, _ := g.V().Count().Next()
fmt.Println("Vertex count:", *count)
// Simple query to verify connection
g.AddV(vertexLabel).Iterate()
count, _ := g.V().HasLabel(vertexLabel).Count().Next()
fmt.Println("Vertex count:", *count)
}

func withConfigs() {
// Connecting to the server with customized configurations
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin",
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL,
func(settings *gremlingo.DriverRemoteConnectionSettings) {
settings.TraversalSource = "g"
settings.NewConnectionThreshold = 4
Expand All @@ -75,7 +74,7 @@ func withConfigs() {
defer driverRemoteConnection.Close()
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

g.AddV().Iterate()
count, _ := g.V().Count().Next()
fmt.Println("Vertex count:", *count)
}
g.AddV(vertexLabel).Iterate()
count, _ := g.V().HasLabel(vertexLabel).Count().Next()
fmt.Println("Vertex count:", *count)
}
3 changes: 2 additions & 1 deletion glv-examples/gremlin-go/modern_traversals.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ import (
var __ = gremlingo.T__
var T = gremlingo.T
var P = gremlingo.P
var serverURL = "ws://localhost:8182/gremlin"

func main() {
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
if err != nil {
fmt.Println(err)
return
Expand Down
8 changes: 7 additions & 1 deletion gremlin-go/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,16 @@ services:
- RUN_BASIC_AUTH_INTEGRATION_TESTS=true
- GREMLIN_SOCKET_SERVER_URL=ws://gremlin-socket-server-go
- GREMLIN_SOCKET_SERVER_CONFIG_PATH=/go_app/gremlin-socket-server/conf/test-ws-gremlin.yaml
- VERTEX_LABEL=go-example
working_dir: /go_app
command: >
bash -c "go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
&& go test -v -json ./... -race -covermode=atomic -coverprofile=\"coverage.out\" -coverpkg=./... | gotestfmt"
&& go test -v -json ./... -race -covermode=atomic -coverprofile=\"coverage.out\" -coverpkg=./... | gotestfmt
&& echo 'Running examples...'
&& go run examples/basic_gremlin.go
&& go run examples/connections.go
&& go run examples/modern_traversals.go
&& echo 'All examples completed successfully'"
depends_on:
gremlin-server-test:
condition: service_healthy
Expand Down
25 changes: 18 additions & 7 deletions gremlin-go/examples/basic_gremlin.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,23 @@ package main

import (
"fmt"
"os"

"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

var serverURL = getEnv("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
var vertexLabel = getEnv("VERTEX_LABEL", "person")

func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}

func main() {
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)
if err != nil {
fmt.Println(err)
return
Expand All @@ -35,9 +46,9 @@ func main() {
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

// Basic Gremlin: adding and retrieving data
v1, err := g.AddV("person").Property("name", "marko").Next()
v2, err := g.AddV("person").Property("name", "stephen").Next()
v3, err := g.AddV("person").Property("name", "vadas").Next()
v1, err := g.AddV(vertexLabel).Property("name", "marko").Next()
v2, err := g.AddV(vertexLabel).Property("name", "stephen").Next()
v3, err := g.AddV(vertexLabel).Property("name", "vadas").Next()
v1Vertex, err := v1.GetVertex()
v2Vertex, err := v2.GetVertex()
v3Vertex, err := v3.GetVertex()
Expand All @@ -58,12 +69,12 @@ func main() {
}

// Retrieve the data from the "marko" vertex
marko, err := g.V().Has("person", "name", "marko").Values("name").Next()
marko, err := g.V().Has(vertexLabel, "name", "marko").Values("name").Next()
fmt.Println("name:", marko.GetString())

// Find the "marko" vertex and then traverse to the people he "knows" and return their data
peopleMarkoKnows, err := g.V().Has("person", "name", "marko").Out("knows").Values("name").ToList()
peopleMarkoKnows, err := g.V().Has(vertexLabel, "name", "marko").Out("knows").Values("name").ToList()
for _, person := range peopleMarkoKnows {
fmt.Println("marko knows", person.GetString())
}
}
}
39 changes: 23 additions & 16 deletions gremlin-go/examples/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ package main

import (
"fmt"
"os"

"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

var serverURL = getEnv("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")
var vertexLabel = getEnv("VERTEX_LABEL", "connection")

func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}

func main() {
withRemote()
withConfigs()
}

func withRemote() {
// Creating the connection to the server
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
// Creating the connection to the server
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL)

// Error handling
if err != nil {
Expand All @@ -43,22 +54,18 @@ func withRemote() {
// Cleanup
defer driverRemoteConnection.Close()

// Creating the graph traversal
// Creating the graph traversal
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

// Drop existing vertices
prom := g.V().Drop().Iterate()
<-prom

// Simple query to verify connection
g.AddV().Iterate()
count, _ := g.V().Count().Next()
fmt.Println("Vertex count:", *count)
// Simple query to verify connection
g.AddV(vertexLabel).Iterate()
count, _ := g.V().HasLabel(vertexLabel).Count().Next()
fmt.Println("Vertex count:", *count)
}

func withConfigs() {
// Connecting to the server with customized configurations
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin",
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL,
func(settings *gremlingo.DriverRemoteConnectionSettings) {
settings.TraversalSource = "g"
settings.NewConnectionThreshold = 4
Expand All @@ -75,7 +82,7 @@ func withConfigs() {
defer driverRemoteConnection.Close()
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection)

g.AddV().Iterate()
count, _ := g.V().Count().Next()
fmt.Println("Vertex count:", *count)
}
g.AddV(vertexLabel).Iterate()
count, _ := g.V().HasLabel(vertexLabel).Count().Next()
fmt.Println("Vertex count:", *count)
}
14 changes: 13 additions & 1 deletion gremlin-go/examples/modern_traversals.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,28 @@ package main

import (
"fmt"
"os"

"github.com/apache/tinkerpop/gremlin-go/v3/driver"
)

var __ = gremlingo.T__
var T = gremlingo.T
var P = gremlingo.P
var serverURL = getEnv("GREMLIN_SERVER_URL", "ws://localhost:8182/gremlin")

func getEnv(key, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
}
return defaultValue
}

func main() {
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("ws://localhost:8182/gremlin")
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection(serverURL,
func(settings *gremlingo.DriverRemoteConnectionSettings) {
settings.TraversalSource = "gmodern"
})
if err != nil {
fmt.Println(err)
return
Expand Down
Loading