-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathredis.go
More file actions
53 lines (46 loc) · 1.67 KB
/
redis.go
File metadata and controls
53 lines (46 loc) · 1.67 KB
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
48
49
50
51
52
53
package main
import (
"context"
"fmt"
"os"
"github.com/stackitcloud/stackit-sdk-go/core/config"
redis "github.com/stackitcloud/stackit-sdk-go/services/redis/v1api"
)
func main() {
projectId := "PROJECT_ID" // the uuid of your STACKIT project
planId := "PLAN_ID"
// Create a new API client, that uses default authentication and configuration
redisClient, err := redis.NewAPIClient(
config.WithRegion("eu01"),
)
if err != nil {
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
os.Exit(1)
}
// Get the redis instances for your project
getInstancesResp, err := redisClient.DefaultAPI.ListInstances(context.Background(), projectId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `GetInstances`: %v\n", err)
} else {
fmt.Printf("Number of instances: %v\n", len(getInstancesResp.Instances))
}
// Get the redis offerings for your project
getOfferingsResp, err := redisClient.DefaultAPI.ListOfferings(context.Background(), projectId).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `GetOfferings`: %v\n", err)
} else {
fmt.Printf("Offerings: %+v\n", getOfferingsResp.Offerings)
}
// Create a redis Instance
createInstancePayload := redis.CreateInstancePayload{
InstanceName: "exampleInstance",
Parameters: &redis.InstanceParameters{},
PlanId: planId,
}
createInstanceResp, err := redisClient.DefaultAPI.CreateInstance(context.Background(), projectId).CreateInstancePayload(createInstancePayload).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `CreateInstance`: %v\n", err)
} else {
fmt.Printf("Created instance with instance id \"%s\".\n", createInstanceResp.InstanceId)
}
}