From the message error, I undestood that you may need a valid authorization header that often includes generating a signature with the primary key :
package main
import (
"fmt"
"net/http"
"github.com/apache/tinkerpop/gremlingo"
)
func createGremlinClient() *gremlingo.Client {
endpoint := "wss://your-account.gremlin.cosmos.azure.com:443/gremlin"
primaryKey := "your-primary-key"
settings := &gremlingo.ConnectionSettings{
TraversalSource: "g",
Mime: gremlingo.GraphSON3MimeType,
WsPingInterval: 60, // Ping interval in seconds to keep the connection alive
WsReadBufferSize: 1024,
WsWriteBufferSize: 1024,
MaxConcurrentUsage: 4,
Authentication: gremlingo.AuthInfo{
Header: http.Header{
"Authorization": []string{gremlingo.BuildGremlinAuthorizationHeader(gremlingo.AuthInfo{
Username: "/dbs/your-database/colls/your-collection",
Password: primaryKey,
})},
},
},
}
// Here you need to create a new Gremlin client
client, err := gremlingo.NewClient(endpoint, settings)
if err != nil {
fmt.Println("Failed to create Gremlin client:", err)
return nil
}
return client
}
func main() {
client := createGremlinClient()
if client == nil {
fmt.Println("Failed to connect to Cosmos DB")
return
}
fmt.Println("Connected to Cosmos DB with Gremlin successfully!")
}