Created
June 19, 2023 15:58
-
-
Save monirz/a8f308fdec5ffcd68e7cb26e8628917b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"crypto/tls" | |
"fmt" | |
"log" | |
"os" | |
gremlingo "github.com/apache/tinkerpop/gremlin-go/v3/driver" | |
) | |
func main() { | |
// Creating the connection to the server. | |
driverRemoteConnection, err := gremlingo.NewDriverRemoteConnection("wss://localhost:8182/gremlin", | |
func(settings *gremlingo.DriverRemoteConnectionSettings) { | |
settings.TraversalSource = "g" | |
settings.TlsConfig = &tls.Config{InsecureSkipVerify: true} | |
}) | |
if err != nil { | |
fmt.Println("Error creating driver remote connection:", err) | |
return | |
} | |
log.Println("debug before") | |
// Creating graph traversal | |
g := gremlingo.Traversal_().WithRemote(driverRemoteConnection) | |
// Insert query | |
_, err = g.AddV("Person").Property("name", "John").Property("age", 30).Next() | |
if err != nil { | |
fmt.Println("Error inserting data:", err) | |
driverRemoteConnection.Close() | |
return | |
} | |
log.Println("Data inserted successfully.") | |
// Perform list traversal | |
results, err := g.V().HasLabel("Person").Values("name").ToList() | |
if err != nil { | |
fmt.Println("Error performing list traversal:", err) | |
driverRemoteConnection.Close() | |
return | |
} | |
// Print results | |
fmt.Println("List of names:") | |
for _, r := range results { | |
fmt.Println(r.GetString()) | |
} | |
log.Println("debug after") | |
// Wait for user input before closing the connection | |
reader := bufio.NewReader(os.Stdin) | |
fmt.Println("Press Enter to close the connection...") | |
reader.ReadLine() | |
// Close the connection explicitly | |
driverRemoteConnection.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment