Go
This section is intended to help Go developers get started using the Fauna Go driver for application development.
Supported Go versions
Currently, the driver is tested on the following Go versions:
-
1.11
-
1.12
-
1.13
-
1.14
Installation
To get the latest version run:
go get github.com/fauna/faunadb-go/v4/faunadb
Please note that the driver undergoes breaking changes from time to time. It is recommended to use one of the following methods instead:
Example application
The following example code runs a bare-bones Go application which
creates a new document in a
collection called People
.
Prerequisites
-
A Fauna account. If you don’t have one, see the dashboard quick start for help getting set up.
-
A supported version of Go and the Fauna Go driver. See Installation for driver installation help.
Procedure
-
Navigate to the Fauna Dashboard
Log in to your Fauna account at Fauna Dashboard if you’re not already logged in.
-
Create a new database
Click NEW DATABASE. Select the
Classic
region group. -
Create a new collection
Click NEW COLLECTION. Name your new collection
People
and save it. -
Create an access key
Click SECURITY in the left-side navigation menu. Create a new key for your database. Be sure to save the key’s secret in a safe place, as it is only displayed once.
-
Create a local environment variable with your access key’s secret
On MacOS and Linux systems, enter the following in a terminal window:
export FAUNADB_SECRET=<your-secret>
For Windows systems, enter the following in a terminal window:
set FAUNADB_SECRET=<your secret>
For either example, replace
<your secret>
with the secret for the access key that you created. -
Create a local application file
With your preferred editor, create a file called
test.go
with the following contents:The above example app uses the
Create
function to create a new document in thePeople
collection. -
Run your application
In a terminal window, run the application:
go run test.go
You should see results similar to this:
map[data:map[age:52 first:Linus last:Torvalds] ref:{324878383054848512 0xc000200300 0xc000200300 <nil>} ts:1646087019880000]
If you get an error, check to make sure your secret is correct.
Next steps
Now that your development environment is set up, you’re ready to start developing more complex applications. The following resources can help.
Is this article helpful?
Tell Fauna how the article can be improved:
Visit Fauna's forums
or email docs@fauna.com
Thank you for your feedback!