We encourage you to try the package in your projects, just keep these caveats in mind, please:
This is a work in progress. Not all of the Cumulocity IoT REST API is covered, and the HTTP client is very simple. In the future the HTTP Client will be improved to support retries on failures, client side rate limiting, prometheus api metrics, mqtt client.
There are no guarantees on API stability. The general mechanics of the golang API are still being worked out. The balance between helpers and clarity is still being found. Given limited access to all available Cumulocity IoT versions, compatibility to all Cumulocity IoT versions is not guaranteed, however since Cumulocity IoT takes an additive approach to new features, it is more likely that the new features will be missing rather than existing API breaking (excluding deprecated features)
Usage
Add the package to your project using go get:
go get -u github.com/reubenmiller/go-c8y/c8y
Create a main.go file with the following
package main
import (
"context"
"log"
"github.com/reubenmiller/go-c8y/pkg/c8y"
)
func main() {
// Create the client from the following environment variables
// C8Y_HOST, C8Y_TENANT, C8Y_USER, C8Y_PASSWORD
client := c8y.NewClientFromEnvironment(nil, false)
// Get list of alarms with MAJOR Severity
alarmCollection, _, err := client.Alarm.GetAlarms(
context.Background(),
&c8y.AlarmCollectionOptions{
Severity: "MAJOR",
},
)
// Always check for errors
if err != nil {
log.Fatalf("Could not retrieve alarms. %s", err)
}
log.Printf("Total alarms: %d", len(alarmCollection.Alarms))
}