Go is one of the Neo4j supported languages and an official driver is provided. Official drivers connect to the databases using BOLT protocol (HTTP is not available).

The 4.0 release of the official Go driver is not available yet and there is currently no release date available. The following article is about the 1.8 version of this driver, built for Neo4j 3.x.

This driver is compatible with databases on 4.x versions, although the database available functionality could be limited by the driver.

📘

About connection parameters

We've used test credentials for all the following examples. Please replace them with your real connection parameters.

You'll find all the required information to connect to your database on our admin panel if you navigate to the Connection section. More on connecting to your database here

This section is intended to provide a small working example to connect to a GrapheneDB database using the Go driver. To get more detailed information, visit the driver web page: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/neo4j

A C connector called seabolt is needed to get the driver running. Please, find more information about how to install it at https://github.com/neo4j-drivers/seabolt

You can install the latest version of the driver using go get or dep commands:

go get github.com/neo4j/neo4j-go-driver

Or

dep ensure github.com/neo4j/neo4j-go-driver

Setting up the connection:

var (
	driver neo4j.Driver
	session neo4j.Session
	result neo4j.Result
	err error
)

driver, err := neo4j.NewDriver("bolt://db-jidgsytyxo1r31sd4ker.graphenedb.com:24786", neo4j.BasicAuth("admin", "b.P0shGn2gvpUD.9RAHyuY4QXkkUK7w", ""), func(c *neo4j.Config) {
	c.Encrypted = true
})
if err != nil {
	return "", err
}
defer driver.Close()

You can test the connection by running a simple query of the Movies dataset example:

if session, err = driver.Session(neo4j.AccessModeRead); err != nil {
      return err
}
defer session.Close()

Result, err = session.Run("MATCH (:Person {name: 'Tom Hanks'})-[:ACTED_IN]->(tomHanksMovies) RETURN movies")

if err != nil {
      return err
}

for result.Next() {
      fmt.Printf(result.Record().Get("movies"))
}

If err = result.Err(); err != nil {
      return err
}