Go SDK¶
rsodev-go is the Go client for the platform's API, with typed operations for everything a
tenant can manage. The command-line client and the Terraform provider
are built on it. It is open source:
github.com/theorigamicorporation/rsodev-go,
with its API documented on
pkg.go.dev.
- Standard library only; one package to import.
- A
context.Contexton every call. - Reads are retried on transient failures; writes are sent once.
- Waiters for objects that are created in the background.
- Errors sorted into a few kinds you can act on.
Install¶
go get github.com/theorigamicorporation/rsodev-go
Go 1.23 or newer.
Quick start¶
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/theorigamicorporation/rsodev-go/platform"
)
func main() {
c, err := platform.New(
platform.WithTenant(os.Getenv("RSO_TENANT")),
platform.WithServiceAccount(os.Getenv("RSO_SERVICE_ACCOUNT_NAME"), os.Getenv("RSO_SERVICE_ACCOUNT_SECRET")),
)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
_, err = c.CreateApp(ctx, platform.AppInput{
Name: "web",
Template: platform.AppTemplate{Spec: platform.AppSpec{Containers: []platform.AppContainer{{
Image: "registry.example.com/web:1.0.0",
Ports: []platform.ContainerPort{{ContainerPort: 8080}},
}}}},
})
if err != nil {
log.Fatal(err)
}
app, err := c.WaitAppReady(ctx, "web", platform.WaitOptions{})
if err != nil {
log.Fatal(err)
}
fmt.Println("serving at", *app.Status.URL)
}
Sign in¶
| Who | How |
|---|---|
| Automation | platform.WithServiceAccount(name, secret) with a service account. The client signs in on the first call and renews the token before it expires. |
| A person | platform.OAuth{}: StartDevice returns a link and a code to show, WaitDevice returns the session once the person confirmed it. Pass a platform.RefreshingSource to WithTokenSource; its Save hook lets you keep the session between runs. |
| A ready token | platform.WithAccessToken(token). The client cannot renew it. |
A client without WithTenant can ask who signed in and which tenants they belong to (Me), which
is how a tool lets the person pick one.
Sign-in endpoints and the client id are read from the API's
configuration document unless you set them with
WithTokenURL and WithClientID.
What it covers¶
| Product | Operations |
|---|---|
| Apps | list, get, create, update, delete, logs, wait until ready |
| Instances | list, get, templates, create (and wait), start, stop, reboot, resize, resize disk, delete |
| PostgreSQL | clusters, databases, backups: enable, schedule, back up now, restore |
| Object storage | buckets, access keys, bucket notifications |
| Queues and topics | queues, topics, subscriptions, credentials, publish, receive |
| Webhooks | list, get, create, update, resume, delete |
| Scheduled jobs and messages | create, update, suspend, run now, runs and logs, delete |
| Networking | external services, ingress routes, middlewares |
| Kubernetes | clusters, node pools, upgrade, kubeconfig and token |
| Registries, secrets, SSH keys, volumes | list, get, create, delete; registry credentials |
| Access | service accounts, roles, grants, access to some objects only, labels |
| Account | who am I, permissions, quota, platform events |
| AI models | list models, streaming chat |
Anything else the API offers is one call away with c.Do(ctx, query, variables, &out).
Errors, paging and waiting¶
Refusals come back as *platform.Error; platform.KindOf(err) sorts any error:
_, err := c.CreateBucket(ctx, "assets")
switch platform.KindOf(err) {
case platform.KindConflict: // already exists
case platform.KindQuota: // the tenant's quota does not allow it
case platform.KindForbidden: // this identity may not do it
case platform.KindNotFound, platform.KindInvalid, platform.KindUnauthenticated, platform.KindUnavailable:
}
IsNotFound, IsConflict, IsQuotaExceeded, IsForbidden and IsUnauthenticated are shorthands.
- Lists that page have a
…Page(ctx, ListOptions)method returning aPage[T]with the total; theList…methods collect every page for you. Wait…methods poll until an object is usable.WaitOptionssets the interval and the timeout (one second and two minutes by default).- Reads are tried three times with a short backoff;
WithRetrychanges that.
You name a tenant and, optionally, a region. The platform decides where things run.