Skip to main content

Go SDK

The clarify-go module can be installed with:

go get "github.com/clarify/clarify-go@latest"

This library is a great option to write Clarify integrations if your main concern is type safety, performance or portability. The SDK expose all API methods from API version v1.1, as well as an automation package that can help you to build automated flows for cleaning up meta-data when publishing signals.

How portable is Go?

Because Go programs are mostly statically linked, you can usually distribute your application by copying the compiled binary only. If you don't develop on and build for the same OS or CPU architecture, Go binaries can be easily cross-compiled.

If your infrastructure rely on Docker and/or an equivalent container run-time, Go binaries can be used with scratch and distroless container images to reduce the attack-surface compared to full distribution images.

Example program writing time-series data to Clarify:

package main

import (
"context"
"encoding/json"
"os"
"time"

clarify "github.com/clarify/clarify-go"
"github.com/clarify/clarify-go/fields"
"github.com/clarify/clarify-go/views"
)

func main() {
creds, err := clarify.CredentialsFromFile("clarify-credentials.json")
if err != nil {
panic(err)
}

ctx := context.Background()
client := creds.Client(ctx)

t0 := fields.AsTimestamp(time.Now()).Truncate(time.Hour)
t1 := t0.Add(15 * time.Minute)
t2 := t1.Add(15 * time.Minute)
t3 := t2.Add(15 * time.Minute)
t4 := t0.Add(24 * time.Hour)
df := views.DataFrame{
"banana-stand/amount": {t0: 250000, t4: 0},
"banana-stand/status": {t0: 0, t1: 0, t2: 1, t3: 1, t4: 0},
}

result, err := client.Insert(df).Do(ctx)
if err != nil {
panic(err)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(result)
}

For more information on the Go SDK, check out the GitHub repository and explore the rest of our examples. For detailed reference, check out the reference documentation. If you are new to Go, you can check out the Go learn page.