Skip to content

Mr-Destructive/turso-go

Repository files navigation

Turso Golang Client

This is a Golang client for interacting with the Turso API. It provides methods for:

  • Managing API tokens
  • Tracking Database Usage
  • Managing Logical DBs and Instances

Installation

go get github.com/mr-destructive/turso-go

Usage

package main

import (
    "fmt"
    "github.com/mr-destructive/turso-go"
)

func main() {
    client := turso.NewClient("", "YOUR_API_TOKEN")
    tokens, err := client.Tokens.List()
    if err != nil {
        panic(err)
    }
    fmt.Println(tokens)
}
  • Create a new client, first parameter is the Turso API base URL (for the API incase of self hosted), leave empty if using turso.
  • Provide the API token by logging in to the CLI

Authentication

The client must be created with a valid API token. Get an API token from the Turso CLI.

  • The token will be automatically included in all requests to the API.

Organizations

  • Get all the organisations for the authenticated user:
client := turso.NewClient("", "YOUR_API_TOKEN")

orgs, err := client.Organizations.List()

if err != nil {
    panic(err)
}
fmt.Println(orgs)
  • Get members with their roles in a given organisation:
client := turso.NewClient("", "YOUR_API_TOKEN")

// provide the org slug
members, err := client.Organizations.Members("org_slug")

if err != nil {
    panic(err)
}
fmt.Println(orgs)

Databases

  • Get all the logical DBs for the organisation:
// provide the org slug
logicalDBs, err := client.Organizations.Databases("org_slug")
fmt.Println(logicalDBs)
  • Get the monthly usage for the database in the organisation:
// provide the org slug and db name
usage, err := client.Organizations.DBUsage("org_slug", "my_db")
fmt.Println(usage)

Instances

  • Get all the instances for the organisation:
// provide the org slug and db name
instances, err := client.Organizations.Instances("org_slug", "my_db")
fmt.Println(instances)

References