Skip to content

Commit 6963664

Browse files
Add sqlserverflex example (#538)
* Add sqlserverflex example * Update examples/sqlserverflex/sqlserverflex.go Co-authored-by: Vicente Pinto <[email protected]> * Update examples/sqlserverflex/sqlserverflex.go Co-authored-by: Vicente Pinto <[email protected]> * Fixes for MongoDB and PostgreSQL --------- Co-authored-by: Vicente Pinto <[email protected]>
1 parent 73eb08d commit 6963664

File tree

6 files changed

+97
-2
lines changed

6 files changed

+97
-2
lines changed

examples/mongodbflex/mongodbflex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func main() {
2727
// Get the MongoDB Flex instances for your project
2828
getInstancesResp, err := mongodbflexClient.ListInstances(context.Background(), projectId).Tag("tag").Execute()
2929
if err != nil {
30-
fmt.Fprintf(os.Stderr, "Error when calling `GetInstances`: %v\n", err)
30+
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
3131
os.Exit(1)
3232
}
3333
items := *getInstancesResp.Items

examples/postgresflex/postgresflex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func main() {
2626
// Get the postgresql instances for your project
2727
getInstancesResp, err := postgresflexClient.ListInstances(context.Background(), projectId).Execute()
2828
if err != nil {
29-
fmt.Fprintf(os.Stderr, "Error when calling `GetInstances`: %v\n", err)
29+
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
3030
os.Exit(1)
3131
}
3232
items := *getInstancesResp.Items

examples/sqlserverflex/go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module github.com/stackitcloud/stackit-sdk-go/examples/sqlserverflex
2+
3+
go 1.18
4+
5+
require github.com/stackitcloud/stackit-sdk-go/core v0.12.0
6+
7+
require (
8+
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
9+
github.com/google/uuid v1.6.0 // indirect
10+
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v0.2.0
11+
)

examples/sqlserverflex/go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
2+
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
3+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
5+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
6+
github.com/stackitcloud/stackit-sdk-go/core v0.12.0 h1:auIzUUNRuydKOScvpICP4MifGgvOajiDQd+ncGmBL0U=
7+
github.com/stackitcloud/stackit-sdk-go/core v0.12.0/go.mod h1:mDX1mSTsB3mP+tNBGcFNx6gH1mGBN4T+dVt+lcw7nlw=
8+
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v0.2.0 h1:aIXxXx6u4+6C02MPb+hdItigeKeen7m+hEEG+Ej9sNs=
9+
github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex v0.2.0/go.mod h1:fQJOQMfasStZ8J9iGX0vTjyJoQtLqMXJ5Npb03QJk84=
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
8+
"github.com/stackitcloud/stackit-sdk-go/core/config"
9+
"github.com/stackitcloud/stackit-sdk-go/core/utils"
10+
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex"
11+
"github.com/stackitcloud/stackit-sdk-go/services/sqlserverflex/wait"
12+
)
13+
14+
func main() {
15+
// Specify the project ID
16+
projectId := "PROJECT_ID"
17+
18+
// Specify instance configuration options
19+
flavorId := "FLAVOR_ID"
20+
version := "VERSION"
21+
22+
ctx := context.Background()
23+
24+
// Create a new API client, that uses default authentication and configuration
25+
sqlserverflexClient, err := sqlserverflex.NewAPIClient(
26+
config.WithRegion("eu01"),
27+
)
28+
if err != nil {
29+
fmt.Fprintf(os.Stderr, "Creating API client: %v\n", err)
30+
os.Exit(1)
31+
}
32+
33+
// Get the SQLServer Flex instances for your project
34+
getInstancesResp, err := sqlserverflexClient.ListInstances(ctx, projectId).Execute()
35+
if err != nil {
36+
fmt.Fprintf(os.Stderr, "Error when calling `ListInstances`: %v\n", err)
37+
os.Exit(1)
38+
}
39+
items := *getInstancesResp.Items
40+
fmt.Printf("Number of instances: %v\n", len(items))
41+
42+
// Create an instance
43+
createInstancePayload := sqlserverflex.CreateInstancePayload{
44+
Name: utils.Ptr("my-instance"),
45+
FlavorId: utils.Ptr(flavorId),
46+
Version: utils.Ptr(version),
47+
}
48+
instance, err := sqlserverflexClient.CreateInstance(ctx, projectId).CreateInstancePayload(createInstancePayload).Execute()
49+
if err != nil {
50+
fmt.Fprintf(os.Stderr, "Error creating SQL Server Flex instance: %v\n", err)
51+
}
52+
instanceId := *instance.Id
53+
54+
_, err = wait.CreateInstanceWaitHandler(ctx, sqlserverflexClient, projectId, instanceId).WaitWithContext(ctx)
55+
if err != nil {
56+
fmt.Fprintf(os.Stderr, "Error when waiting for SQL Server Flex instance creation: %v\n", err)
57+
}
58+
59+
fmt.Printf("Created SQL Server Flex instance \"%s\".\n", instanceId)
60+
61+
// Delete an instance
62+
err = sqlserverflexClient.DeleteInstance(ctx, projectId, instanceId).Execute()
63+
64+
if err != nil {
65+
fmt.Fprintf(os.Stderr, "Error deleting SQL Server Flex instance: %v\n", err)
66+
}
67+
68+
_, err = wait.DeleteInstanceWaitHandler(ctx, sqlserverflexClient, projectId, instanceId).WaitWithContext(ctx)
69+
if err != nil {
70+
fmt.Fprintf(os.Stderr, "Error when waiting for SQL Server Flex instance deletion: %v\n", err)
71+
}
72+
73+
fmt.Printf("Deleted SQL Server Flex instance \"%s\".\n", instanceId)
74+
}

go.work

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use (
2626
./examples/secretsmanager
2727
./examples/serviceaccount
2828
./examples/ske
29+
./examples/sqlserverflex
2930
./examples/waiter
3031
./scripts
3132
./services/argus

0 commit comments

Comments
 (0)