Go SDK
A small typed client for the Rivergate API, for services and tools written in Go.
Install
go get github.com/rivergate-dev/rivergate-sdk-go
The package is imported as rivergate.
Create a client
import (
"context"
rivergate "github.com/rivergate-dev/rivergate-sdk-go"
)
func run(ctx context.Context, token string) error {
client, err := rivergate.NewClient("https://rivergate.example.com", token)
if err != nil {
return err
}
organizations, err := client.ListOrganizations(ctx)
if err != nil {
return err
}
_ = organizations
return nil
}
- The client holds the bearer token in memory only. Where you keep it is up to you.
- Plain HTTP is accepted only for loopback addresses. Use HTTPS everywhere else.
- Supply your own transport with
rivergate.WithHTTPClient.
Reading a secret value
value, err := client.GetSecretValue(ctx, orgID, projectID, environmentID, secretID, 0)
if err != nil {
return err
}
_ = value // Do not log or persist this.
Pass 0 as the version for the current value, or a version number for a specific one. The call is authorized and audited server-side.
Go strings cannot be reliably erased. Do not log or persist the value, and clear any byte slices you derive from it when practical.
Typed operations
| Method | Purpose |
|---|---|
ListOrganizations | Organizations you belong to. |
ListProjects, ListEnvironments | Scoped listings. |
ListSecrets | Cursor-paginated secret metadata. |
GetSecret | One secret’s metadata. |
CreateSecret, UpdateSecret | Create a secret, or append a new version. |
ListSecretVersions | Version history with before and limit. |
RollbackSecret | Make a historical version current as a new version. |
GetSecretValue | Explicit value read, current or by version. |
Do | Generic call that supports every documented route. |
Calling any route
var out map[string]any
err := client.Do(ctx, "GET",
"/api/v1/organizations/ORG_ID/members", nil, &out)
Handling errors
API failures are returned as *rivergate.APIError, which exposes the HTTP status (StatusCode), a stable error code, a safe message, the request ID and any RetryAfter the server sent. Use the request ID to find the matching server log.
var apiErr *rivergate.APIError
if errors.As(err, &apiErr) {
log.Printf("rivergate error: status=%d code=%s request_id=%s",
apiErr.StatusCode, apiErr.Code, apiErr.RequestID)
}
When the server sends Retry-After, it is parsed into APIError.RetryAfter so your retry logic can respect it.
Workload token exchange
For Kubernetes workloads, the module also provides ExchangeWorkloadToken, which trades a projected ServiceAccount JWT for a short-lived Rivergate token. The Operator uses it internally; see Kubernetes Operator.