Skip to main content

Go idioms

Go uses package names as datatypes, and datatypes as qualifiers, to invoke member functions:

package.Member()
var myvariable package.Typename

Moreover, the package name becomes an object reference to all types and unclassified functions defined within it: e.g.

driver.Function()    // package driver
fmt.Println("hello") // package fmt
os.Exit(0) // package os

There are two Go package components needed for the Go driver. The main go-driver name contains an illegal character, however, so we need to map it to an alias, say a driver for the ArangoDB driver (or something shorter), by importing it as

import (
"github.com/arangodb/go-driver/http"
driver "github.com/arangodb/go-driver"
)

Now we refer to the member functions and types as:

http.NewConnection(..)
driver.NewClient(..)
driver.Database
driver.Collection
 
Help us improve

Anything unclear or buggy in this tutorial? Provide Feedback