Bernhard Reitinger, Technical Director
May 13, 2019
In this tutorial series I would like to introduce on the open source gorex library which is a simple way to access the rexOS API, but also contains various useful tools. As a pre-requisite, you need to install Go (version >=1.12.X) on your machine. Your Go executable should be in your path, you can simply check this by:
> go version
go version go1.12.4 linux/amd64
The gorex SDK provides different abstract levels. The low-level layer implements the official REST API, but also brings more complexity. It keep things simple, gorex offers a simple rexOS API. The simplest Go program you can write is to authenticate and to get a list of your projects.
Make sure that you have registered as a REX user and created a pair of API keys (for details please see here).
Once you have your clientID
and clientSecret
you can create the following simple Go program (please replace the
according credentials with yours).
package main
import (
"fmt"
"github.com/roboticeyes/gorex/http/rexos"
)
var (
rexDomain = "https://rex.robotic-eyes.com"
clientID = "<your clientID>"
clientSecret = "<your clientSecret>"
)
func main() {
controller := rexos.NewController(rexDomain)
// Authenticate
err := controller.Authenticate(clientID, clientSecret)
if err != nil {
fmt.Println("Cannot authenticate to rexOS: ", err)
}
// Get projects
projects, err := controller.GetProjects()
if err != nil {
fmt.Println("Cannot get project list: ", err)
}
fmt.Printf("Found %d projects ...\n\n", len(projects))
for _, p := range projects {
fmt.Println(p.Name)
}
}
Simply run the program with go run main.go
and you should get the list of your projects. You can find the source code
of gorex at Github. The example
folder contains various simple examples to get
started.