Go SDK

github.com/rstglobal/oneanalytics-go is the official Go SDK. Generated from the OpenAPI spec, context.Context-first API, stdlib net/http transport.

Install

go get github.com/rstglobal/oneanalytics-go

Go 1.22+ required.

Quickstart

package main

import (
    "context"
    "fmt"
    "log"
    "os"

    oa "github.com/rstglobal/oneanalytics-go"
)

func main() {
    client, err := oa.New(oa.Config{
        BaseURL: "https://api.analytics.rstglobal.in",
        Token:   os.Getenv("OA_TOKEN"),
    })
    if err != nil {
        log.Fatal(err)
    }

    ctx := context.Background()

    // list workspaces, paginated
    iter := client.Workspaces.ListAll(ctx, oa.ListOptions{Limit: 100})
    for iter.Next() {
        ws := iter.Value()
        fmt.Println(ws.ID, ws.Name)
    }
    if err := iter.Err(); err != nil {
        log.Fatal(err)
    }

    // query a dataset
    result, err := client.Datasets.Query(ctx, datasetID, oa.QueryRequest{
        Dimensions: []oa.Dimension{{ID: "order_date", Grain: "month"}},
        Measures:   []string{"revenue"},
        Filters:    []oa.Filter{{Field: "region", Op: "in", Value: []string{"North", "South"}}},
        Limit:      1000,
    })
    if err != nil {
        log.Fatal(err)
    }
    for _, row := range result.Rows {
        fmt.Println(row)
    }
}

Idempotency

Every Create* method accepts an IdempotencyKey option:

_, err := client.Sharing.Create(ctx, oa.GrantCreate{
    SubjectType:   "report",
    SubjectID:     rptID,
    PrincipalType: "link",
    Actions:       []string{"view"},
}, oa.WithIdempotencyKey("export-2026-04-16-rpt-123"))

Omitted → SDK generates a UUIDv4.

Errors

result, err := client.Datasets.Query(ctx, id, req)
var oaErr *oa.APIError
if errors.As(err, &oaErr) {
    switch oaErr.Code {
    case "query/timeout":
        // retry with simpler query
    case "rate-limit/burst":
        time.Sleep(oaErr.RetryAfter)
    }
}

APIError has Code, Status, TraceID, Detail, DocURL, RetryAfter.

Retries

Default http.RoundTripper is wrapped with a retry transport: 5 attempts, exponential backoff, jitter, cap 30 s total. Disable or customise:

client, _ := oa.New(oa.Config{
    Token:   token,
    Retry:   oa.RetryPolicy{MaxAttempts: 3, MaxDelay: 10 * time.Second},
})

Context cancellation

Every method takes a context.Context. Cancel the context and the in-flight HTTP call is cancelled too — clean shutdowns guaranteed.

Structured logging

Pluggable Logger interface; satisfies log/slog.Logger out of the box:

client, _ := oa.New(oa.Config{Token: token, Logger: slog.Default()})

Streaming query via Apache Arrow

stream, err := client.Datasets.QueryArrow(ctx, id, req)
defer stream.Close()
for stream.Next() {
    batch := stream.RecordBatch()   // *arrow.Record
    // ...
}

20× faster than JSON. Requires github.com/apache/arrow/go/v14.