https://github.com/komminarlabs/cratedb
CrateDB Cloud API Client Go Library
https://github.com/komminarlabs/cratedb
api cratedb cratedb-client cratedb-cloud golang
Last synced: 3 months ago
JSON representation
CrateDB Cloud API Client Go Library
- Host: GitHub
- URL: https://github.com/komminarlabs/cratedb
- Owner: komminarlabs
- License: apache-2.0
- Created: 2024-09-10T17:10:54.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-10-07T21:30:03.000Z (8 months ago)
- Last Synced: 2025-01-15T19:23:11.015Z (5 months ago)
- Topics: api, cratedb, cratedb-client, cratedb-cloud, golang
- Language: Go
- Homepage: https://pkg.go.dev/github.com/komminarlabs/cratedb
- Size: 96.7 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CrateDB Cloud API Client Go Library
The CrateDB Cloud API client Go library to allow programmatic access to the Cloud products.
## Generated types and API client
This library is generated using [oapi-codegen](https://github.com/oapi-codegen/oapi-codegen) from this [OpenAPI spec](https://console.cratedb.cloud/api/cloud-api-openapi-v1.0.0.json)
### Generate
```go
go generate ./...
```## Usage
### Environment variables
```bash
export CRATEDB_BASE_URL="https://console.cratedb.cloud/"
export CRATEDB_API_KEY="crate_09NZV-SXkpX3feMJWXxnSNY2AAa98RlKkxqvqdQBlfC"
export CRATEDB_API_SECRET="S5ChS_eQHoUxzplSOv11xQrFRD8W_G-I5Z43w56RIqn"
```### Sample code to list database tokens
```go
package mainimport (
"context"
"io"
"net/http""github.com/caarlos0/env/v11"
"github.com/komminarlabs/cratedb"
)type CratedbConfig struct {
BaseURL string `env:"CRATEDB_BASE_URL"`
ApiKey string `env:"CRATEDB_API_KEY"`
ApiSecret string `env:"CRATEDB_API_SECRET"`
}func main() {
cfg := CratedbConfig{}
opts := env.Options{RequiredIfNoDef: true}err := env.ParseWithOptions(&cfg, opts)
if err != nil {
panic(err)
}ctx := context.Background()
client, err := cratedb.NewClient(cfg.BaseURL, cratedb.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
req.SetBasicAuth(cfg.ApiKey, cfg.ApiSecret)
return nil
}))
if err != nil {
panic(err)
}resp, err := client.GetApiV2UsersMe(ctx)
if err != nil {
panic(err)
}
defer resp.Body.Close()if resp.StatusCode == http.StatusOK {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
bodyString := string(bodyBytes)
println(bodyString)
}
}
```