Go

Connect your Go applications to Gitana

Latest Version
Version undefined
Date

Current version: v0.1.3. Released Jun 13, 2022

The Gitana Go driver allows you to easily connect your Go applications to the Gitana server.

Currently supports the following functionality:

  • Connect to and refresh access tokens with the API
  • Read platform, branches, repositories, projects, releases
  • Read, query, search, create, update, and delete nodes
  • Manage node translations, versions, associations, attachments
  • Make graphql queries
  • And more!

Installation

Install this driver using the go cli:

go get github.com/gitana/cloudcms-go-driver

Connecting to Gitana

To connect to Gitana, use one of the functions cloudcms.ConnectDefault or cloudcms.Connect.

ConnectDefault looks for a gitana.json file in your working directory, where as Connect allows you to pass the required authentication settings.

The required API key properties for this are:

  • clientKey
  • clientSecret
  • username
  • password
  • baseURL

You can also provide the flag debug: true in your gitana.json / Gitana config object to provide additional request logging.

Connection Examples:

// Connect to Gitana using gitana.json in working directory
session, err := cloudcms.ConnectDefault()
if err != nil {
    fmt.Println(err)
    return
}]

session, err = cloudcms.Connect(&cloudcms.CloudcmsConfig{
    Client_id: "clientId",
    Client_secret: "clientSecret",
    Username: "username",
    Password: "password",
    BaseURL: "baseURL",
})

Examples

Below are some examples of how you might use the driver:

package main

import (
    "github.com/gitana/cloudcms-go-driver"
)

func main() {

    // Connect to Gitana using gitana.json in working directory
    session, err := cloudcms.ConnectDefault()
    if err != nil {
        fmt.Println(err)
        return
    }

    var repositoryId string
 
 
    // List branches
    branches, _ := session.ListBranches(repositoryId, nil)
 
    // Read branch
    branchId := "master"
    branch, _ := session.ReadBranch(repositoryId, branchId)
 
    // Read Node
    node, _ := session.ReadNode(repositoryId, branchId, nodeId)
 
    // Create Node
    nodeObj := cloudcms.JsonObject{
        "title": "Twelfth Night",
        "description": "An old play",
    }
    nodeId, _ := session.createNode(repositoryId, branchId, nodeObj, nil)
 
    // Query Nodes
    query := cloudcms.JsonObject{
        "_type": "store:book",
    }
    pagination := cloudcms.JsonObject{
        "limit": 1,
    }
    queriedNodes, _ session.QueryNodes(repositoryId, branchId, query, pagination)
 
    // Find Nodes
    find := cloudcms.JsonObject{
        "search": "Shakespeare",
        "query": JsonObject{
            "_type": "store:book",
        }
    }
    findNodes, _ := session.FindNodes(repositoryId, branchId, find ,nil)
}

Documentation

The Go driver is a useful library that provides access to the capabilities of Gitana from a programmatic perspective. It is therefore important to first familiarize yourself with the concepts presented in the Gitana Documentation

Check out our Gitana Go Cookbook for recipes and examples using the Go Driver.

Fork the Code

The Gitana Go driver is 100% open-source (Apache 2.0) and so you're free to fork it, extend it and dig into it to learn about how it works.

Bugs / Problems

If you run into a bug, please create an issue so that we can look at it. For production support, please contact us at support@gitana.io or call us directly.

Support and Terms of Use

The Go driver is free to use in your applications and projects. It is fully supported by Gitana.