@@ -21,18 +21,29 @@ package main
2121
2222import  (
2323	"fmt" 
24+ 	"os" 
2425
2526	"github.com/apache/tinkerpop/gremlin-go/v3/driver" 
2627)
2728
29+ var  serverURL  =  getEnv ("GREMLIN_SERVER_URL" , "ws://localhost:8182/gremlin" )
30+ var  vertexLabel  =  getEnv ("VERTEX_LABEL" , "connection" )
31+ 
32+ func  getEnv (key , defaultValue  string ) string  {
33+ 	if  value  :=  os .Getenv (key ); value  !=  ""  {
34+ 		return  value 
35+ 	}
36+ 	return  defaultValue 
37+ }
38+ 
2839func  main () {
2940	withRemote ()
3041	withConfigs ()
3142}
3243
3344func  withRemote () {
34-      // Creating the connection to the server 
35-      driverRemoteConnection , err  :=  gremlingo .NewDriverRemoteConnection ("ws://localhost:8182/gremlin" )
45+ 	 // Creating the connection to the server 
46+ 	 driverRemoteConnection , err  :=  gremlingo .NewDriverRemoteConnection (serverURL )
3647
3748	// Error handling 
3849	if  err  !=  nil  {
@@ -43,22 +54,18 @@ func withRemote() {
4354	// Cleanup 
4455	defer  driverRemoteConnection .Close ()
4556
46-      // Creating the graph traversal 
57+ 	 // Creating the graph traversal 
4758	g  :=  gremlingo .Traversal_ ().WithRemote (driverRemoteConnection )
4859
49-     // Drop existing vertices 
50-     prom  :=  g .V ().Drop ().Iterate ()
51-     <- prom 
52- 
53-     // Simple query to verify connection 
54-     g .AddV ("connection" ).Iterate ()
55-     count , _  :=  g .V ().HasLabel ("connection" ).Count ().Next ()
56-     fmt .Println ("Vertex count:" , * count )
60+ 	// Simple query to verify connection 
61+ 	g .AddV (vertexLabel ).Iterate ()
62+ 	count , _  :=  g .V ().HasLabel (vertexLabel ).Count ().Next ()
63+ 	fmt .Println ("Vertex count:" , * count )
5764}
5865
5966func  withConfigs () {
6067	// Connecting to the server with customized configurations 
61- 	driverRemoteConnection , err  :=  gremlingo .NewDriverRemoteConnection ("ws://localhost:8182/gremlin" ,
68+ 	driverRemoteConnection , err  :=  gremlingo .NewDriverRemoteConnection (serverURL ,
6269		func (settings  * gremlingo.DriverRemoteConnectionSettings ) {
6370			settings .TraversalSource  =  "g" 
6471			settings .NewConnectionThreshold  =  4 
@@ -75,7 +82,7 @@ func withConfigs() {
7582	defer  driverRemoteConnection .Close ()
7683	g  :=  gremlingo .Traversal_ ().WithRemote (driverRemoteConnection )
7784
78-      g .AddV ("connection" ).Iterate ()
79-      count , _  :=  g .V ().HasLabel ("connection" ).Count ().Next ()
80-      fmt .Println ("Vertex count:" , * count )
81- }
85+ 	 g .AddV (vertexLabel ).Iterate ()
86+ 	 count , _  :=  g .V ().HasLabel (vertexLabel ).Count ().Next ()
87+ 	 fmt .Println ("Vertex count:" , * count )
88+ }
0 commit comments