forked from scaleway/scaleway-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_test.go
110 lines (85 loc) · 2.45 KB
/
example_test.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package scalewaysdkgo
import (
"fmt"
"github.com/scaleway/scaleway-sdk-go/api/instance/v1"
"github.com/scaleway/scaleway-sdk-go/api/lb/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/scaleway-sdk-go/scwconfig"
"github.com/scaleway/scaleway-sdk-go/utils"
)
func Example_apiClient() {
// Create a Scaleway client
client, err := scw.NewClient(
scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials
)
if err != nil {
// handle error
}
// Create SDK objects for specific Scaleway Products
instance := instance.NewAPI(client)
lb := lb.NewAPI(client)
// Start using the SDKs
_, _ = instance, lb
}
func Example_apiClientWithConfig() {
// Get Scaleway Config
config, err := scwconfig.Load()
if err != nil {
// handle error
}
// Create a Scaleway client
client, err := scw.NewClient(
scw.WithConfig(config),
)
if err != nil {
// handle error
}
// Create SDK objects for specific Scaleway Products
instance := instance.NewAPI(client)
lb := lb.NewAPI(client)
// Start using the SDKs
_, _ = instance, lb
}
func Example_listServers() {
// Create a Scaleway client
client, err := scw.NewClient(
scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials
)
if err != nil {
// handle error
}
// Create SDK objects for Scaleway Instance product
instanceAPI := instance.NewAPI(client)
// Call the ListServers method on the Instance SDK
response, err := instanceAPI.ListServers(&instance.ListServersRequest{
Zone: utils.ZoneFrPar1,
})
if err != nil {
// handle error
}
// Do something with the response...
fmt.Println(response)
}
func Example_createLoadBalancer() {
// Create a Scaleway client
client, err := scw.NewClient(
scw.WithAuth("ACCESS_KEY", "SECRET_KEY"), // Get your credentials at https://console.scaleway.com/account/credentials
)
if err != nil {
// handle error
}
// Create SDK objects for Scaleway Load Balancer product
lbAPI := lb.NewAPI(client)
// Call the CreateLb method on the LB SDK to create a new load balancer.
newLb, err := lbAPI.CreateLb(&lb.CreateLbRequest{
Name: "My new load balancer",
Description: "This is a example of a load balancer",
OrganizationID: "000a115d-2852-4b0a-9ce8-47f1134ba95a",
Region: utils.RegionFrPar,
})
if err != nil {
// handle error
}
// Do something with the newly created LB...
fmt.Println(newLb)
}