diff --git a/glv-examples/gremlin-go/basic_gremlin.go b/glv-examples/gremlin-go/basic_gremlin.go index 0ab2b1117fd..e95771e6945 100644 --- a/glv-examples/gremlin-go/basic_gremlin.go +++ b/glv-examples/gremlin-go/basic_gremlin.go @@ -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 @@ -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() @@ -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()) } diff --git a/glv-examples/gremlin-go/connections.go b/glv-examples/gremlin-go/connections.go index 3e1f1de174d..467cc946458 100644 --- a/glv-examples/gremlin-go/connections.go +++ b/glv-examples/gremlin-go/connections.go @@ -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 { @@ -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 @@ -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) -} \ No newline at end of file + g.AddV(vertexLabel).Iterate() + count, _ := g.V().HasLabel(vertexLabel).Count().Next() + fmt.Println("Vertex count:", *count) +} diff --git a/glv-examples/gremlin-go/modern_traversals.go b/glv-examples/gremlin-go/modern_traversals.go index a1c9ad83203..7781d3e11c8 100644 --- a/glv-examples/gremlin-go/modern_traversals.go +++ b/glv-examples/gremlin-go/modern_traversals.go @@ -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 diff --git a/gremlin-go/docker-compose.yml b/gremlin-go/docker-compose.yml index 36fafcb4245..611b15dde07 100644 --- a/gremlin-go/docker-compose.yml +++ b/gremlin-go/docker-compose.yml @@ -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 diff --git a/gremlin-go/examples/basic_gremlin.go b/gremlin-go/examples/basic_gremlin.go index 0ab2b1117fd..4220b96a4be 100644 --- a/gremlin-go/examples/basic_gremlin.go +++ b/gremlin-go/examples/basic_gremlin.go @@ -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 @@ -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() @@ -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()) } -} \ No newline at end of file +} diff --git a/gremlin-go/examples/connections.go b/gremlin-go/examples/connections.go index 3e1f1de174d..f2883e371d6 100644 --- a/gremlin-go/examples/connections.go +++ b/gremlin-go/examples/connections.go @@ -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 { @@ -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 @@ -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) -} \ No newline at end of file + g.AddV(vertexLabel).Iterate() + count, _ := g.V().HasLabel(vertexLabel).Count().Next() + fmt.Println("Vertex count:", *count) +} diff --git a/gremlin-go/examples/modern_traversals.go b/gremlin-go/examples/modern_traversals.go index a1c9ad83203..b722b2812d2 100644 --- a/gremlin-go/examples/modern_traversals.go +++ b/gremlin-go/examples/modern_traversals.go @@ -21,6 +21,7 @@ package main import ( "fmt" + "os" "github.com/apache/tinkerpop/gremlin-go/v3/driver" ) @@ -28,9 +29,20 @@ import ( 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