-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (38 loc) · 1.04 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"github.com/singlestore-labs/singlestore-go/management"
)
const apiServiceURL = "https://api.singlestore.com"
func main() {
apiKey := os.Getenv("API_KEY")
if apiKey == "" {
log.Fatal("Environmental variable $API_KEY should be set, visit https://docs.singlestore.com/managed-service/en/reference/management-api.html for details")
}
client, err := management.NewClientWithResponses(apiServiceURL,
management.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
return nil
}),
)
if err != nil {
log.Fatal(err)
}
regions, err := client.GetV0betaRegionsWithResponse(context.TODO())
if err != nil {
log.Fatal(err)
}
if regions.HTTPResponse.StatusCode != http.StatusOK {
log.Fatalf("request returned %s", regions.HTTPResponse.Status)
}
result, err := json.MarshalIndent(regions.JSON200, "", " ")
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s\n", result)
}