Redash API client for Go that supports almost all APIs.
package main
import (
"bytes"
"context"
"fmt"
"time"
"github.com/winebarrel/redash-go/v2"
)
func main() {
client := redash.MustNewClient("https://redash.example.com", "<secret>")
ctx := context.Background()
ds, err := client.CreateDataSource(ctx, &redash.CreateDataSourceInput{
Name: "postgres",
Type: "pg",
Options: map[string]any{
"dbname": "postgres",
"host": "postgres",
"port": 5432,
"user": "postgres",
},
})
if err != nil {
panic(err)
}
query, err := client.CreateQuery(ctx, &redash.CreateQueryInput{
DataSourceID: ds.ID,
Name: "my-query1",
Query: "select 1",
})
if err != nil {
panic(err)
}
var buf bytes.Buffer
// The API prefers to return a cached result.
// If a cached result is not available then a new execution job begins and the job object is returned.
// see https://redash.io/help/user-guide/integrations-and-api/api#Queries
job, err := client.ExecQueryJSON(ctx, query.ID, nil, &buf)
if err != nil {
panic(err)
}
err = client.WaitQueryJSON(ctx, query.ID, job, nil, &buf)
if err != nil {
panic(err)
}
fmt.Println(buf.String())
}
input := &redash.ExecQueryJSONInput{
WithoutOmittingMaxAge: true,
}
job, err := client.ExecQueryJSON(ctx, query.ID, input, nil)
if err != nil {
panic(err)
}
err = client.WaitQueryJSON(ctx, query.ID, job, nil, &buf)
if err != nil {
panic(err)
}
fmt.Println(buf.String())
client := redash.MustNewClient("https://redash.example.com", "<secret>")
client.SetDebug(true)
client.GetStatus(context.Background())
% go run example.go
---request begin---
GET /status.json HTTP/1.1
Host: redash.example.com
Authorization: Key <secret>
Content-Type: application/json
User-Agent: redash-go
---request end---
---response begin---
HTTP/1.1 200 OK
...
{"dashboards_count": 0, "database_metrics": {"metrics": [ ...
hc := &http.Client{
Timeout: 3 * time.Second,
}
client := redash.MustNewClientWithHTTPClient("https://redash.example.com", "<secret>", hc)
client.GetStatus(context.Background())
client0 := redash.MustNewClient("https://redash.example.com", "<secret>")
client := client0.WithoutContext()
client.GetStatus()
client, err := redash.NewClient("https://redash.example.com", "<secret>")
make test
docker compose up -d
make redash-setup
make redash-upgrade-db
make testacc
NOTE:
- local Redash URL: http://localhost:5001
- email:
[email protected]
- password:
password