GoGo driver

This section describes Fauna’s open source Go driver, which provides the resources required to interact with FaunaDB.

Supported Go versions

Currently, the driver is tested on the following Go versions:

  • 1.5

  • 1.6

  • 1.7

  • 1.8

  • 1.9

Install

To get the latest version run:

go get github.com/fauna/faunadb-go/faunadb

Please note that the driver undergoes breaking changes from time to time. It is recommended to use one of the following methods instead:

Using gopkg.in

To get a specific version when using gopkg.in, use:

go get gopkg.in/fauna/faunadb-go.v2/faunadb

Using dep

To get a specific version when using dep, use:

dep ensure -add github.com/fauna/faunadb-go/faunadb@v2.6.0

Importing

For better usage, we recommend that you import this driver with an alias import.

Using gopkg.in

To import a specific version when using gopkg.in, use:

import f "gopkg.in/fauna/faunadb-go.v2/faunadb"

Using dep or go get

To import a specific version when using dep or go get, use:

import f "github.com/fauna/faunadb-go/faunadb"

Usage

Here is an example demonstrating how to use the Go driver to execute a simple query on FaunaDB:

package main

import (
    "fmt"

    f "github.com/fauna/faunadb-go/faunadb"
)

type User struct {
    Name string `fauna:"name"`
}

func main() {
    client := f.NewFaunaClient("your-secret-here")

    res, err := client.Query(f.Get(f.RefClass(f.Collection("user"), "42")))
    if err != nil {
        panic(err)
    }

    var user User

    if err := res.At(f.ObjKey("data")).Get(&user); err != nil {
        panic(err)
    }

    fmt.Println(user)
}

Next steps

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!