Using Neo4j from Go

Goals
If you are a Go developer, this guide provides an overview of options for connecting to Neo4j. While this guide is not comprehensive it will introduce the different drivers and link to the relevant resources.
Prerequisites
You should be familiar with graph database concepts and the property graph model. You should have created an Neo4j AuraDB cloud instance, or installed Neo4j locally

Intermediate

Neo4j for Go Developers

GO

Neo4j provides drivers which allow you to make a connection to the database and develop applications which create, read, update, and delete information from the graph.

Neo4j Go Driver

The Neo4j Go driver is officially supported by Neo4j and connects to the database using the binary bolt protocol. It aims to be minimal, while being idiomatic to Go.

Module version

Make sure your application has been set up to use go modules (there should be a go.mod file in your application root). Add the driver with:

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

If you need to pin a specific 4.x version, you can run this instead:

go get github.com/neo4j/neo4j-go-driver/v4@<4.x tag>

where <4.x tag> is one of the available tag (e.g.: v4.2.4).

func helloWorld(uri, username, password string) (string, error) {
	driver, err := neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""))
	if err != nil {
		return "", err
	}
	defer driver.Close()

	session := driver.NewSession(neo4j.SessionConfig{AccessMode: neo4j.AccessModeWrite})
	defer session.Close()

	greeting, err := session.WriteTransaction(func(transaction neo4j.Transaction) (interface{}, error) {
		result, err := transaction.Run(
			"CREATE (a:Greeting) SET a.message = $message RETURN a.message + ', from node ' + id(a)",
			map[string]interface{}{"message": "hello, world"})
		if err != nil {
			return nil, err
		}

		if result.Next() {
			return result.Record().Values[0], nil
		}

		return nil, result.Err()
	})
	if err != nil {
		return "", err
	}

	return greeting.(string), nil
}

Driver Configuration

From Neo4j version 4.0 and onwards, the default encryption setting is off by default and Neo4j will no longer generate self-signed certificates. This applies to default installations, installations through Neo4j Desktop and Docker images. You can verify the encryption level of your server by checking the dbms.connector.bolt.enabled key in neo4j.conf.

Table 1. Table Scheme Usage
Certificate Type Neo4j Causal Cluster Neo4j Standalone Server Direct Connection to Cluster Member

Unencrypted

neo4j

neo4j

bolt

Encrypted with Full Certificate

neo4j+s

neo4j+s

bolt+s

Encrypted with Self-Signed Certificate

neo4j+ssc

neo4j+ssc

bolt+ssc

Neo4j AuraDB

neo4j+s

N/A

N/A

Please review your SSL Framework settings when going into production. If necessary, you can also generate certificates for Neo4j with Letsencrypt

Name

Version

Authors

neo4j-driver

4.4.3

The Neo4j Team

Neo4j Online Community

Docs

API

The Example Project

The Neo4j example project is a small, one page webapp for the movies database built into the Neo4j tutorial. The front-end page is the same for all drivers: movie search, movie details, and a graph visualization of actors and movies. Each backend implementation shows you how to connect to Neo4j from each of the different languages and drivers.

You can learn more about our small, consistent example project across many different language drivers here. You will find the implementations for all drivers as individual GitHub repositories, which you can clone and deploy directly.

Neo4j Community Drivers

Members of the each programming language community have invested a lot of time and love to develop each one of the community drivers for Neo4j, so if you use any one of them, please provide feedback to the authors.

The community drivers have been graciously contributed by the Neo4j community. Many of them are fully featured and well-maintained, but some may not be. Neo4j does not take any responsibility for their usability.

GoGM: Golang Object Graph Mapper

Author

Eric Solender, CTO and co-founder of Mindstand

Source

https://github.com/mindstand/gogm

Docs

https://github.com/mindstand/gogm/blob/master/README.md