Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mr-destructive/turso-go
Golang Client for Turso platform API -> turso.tech
https://github.com/mr-destructive/turso-go
api-client turso
Last synced: 8 days ago
JSON representation
Golang Client for Turso platform API -> turso.tech
- Host: GitHub
- URL: https://github.com/mr-destructive/turso-go
- Owner: Mr-Destructive
- License: mit
- Created: 2023-10-24T10:05:08.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-19T15:39:42.000Z (5 months ago)
- Last Synced: 2024-08-02T09:26:37.023Z (3 months ago)
- Topics: api-client, turso
- Language: Go
- Homepage: https://pkg.go.dev/github.com/mr-destructive/turso-go
- Size: 45.9 KB
- Stars: 14
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Audit: audit_logs.go
Awesome Lists containing this project
- awesome-turso - turso-go - > turso.tech. (Tools / Community)
README
## Turso Golang Client
This is a Golang client for interacting with the Turso API. It provides methods for:
- [x] Managing API tokens
- [x] Tracking Database Usage
- [x] Managing Logical DBs and Instances## Installation
```bash
go get github.com/mr-destructive/turso-go
```## Usage
```go
package mainimport (
"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](https://docs.turso.tech/reference/turso-cli).
- The token will be automatically included in all requests to the API.
### Organizations
- Get all the organisations for the authenticated user:
```go
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:
```go
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:
```go
// provide the org slug
logicalDBs, err := client.Organizations.Databases("org_slug")
fmt.Println(logicalDBs)
```- Get the monthly usage for the database in the organisation:
```go
// 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:
```go
// provide the org slug and db name
instances, err := client.Organizations.Instances("org_slug", "my_db")
fmt.Println(instances)
```## References
- [Turso Platform REST API docs](https://docs.turso.tech/reference/platform-rest-api/)
- [Turso CLI](https://docs.turso.tech/reference/turso-cli)