@@ -52,7 +52,7 @@ svc := service.New(client.New(username, password))
5252_ , err := svc.GetAccount ()
5353
5454if err != nil {
55- panic (" Invalid credentials" )
55+ panic (" Invalid credentials" )
5656}
5757```
5858
@@ -70,11 +70,11 @@ _, err := svc.GetAccount()
7070
7171// Handle errors in general
7272if (err != nil ) {
73- // Handle service errors specifically
74- if serviceError , ok := err.(*upcloud.Error ); ok {
75- fmt.Println (serviceError.ErrorCode )
76- fmt.Println (serviceError.ErrorMessage )
77- }
73+ // Handle service errors specifically
74+ if serviceError , ok := err.(*upcloud.Error ); ok {
75+ fmt.Println (serviceError.ErrorCode )
76+ fmt.Println (serviceError.ErrorMessage )
77+ }
7878}
7979````
8080
@@ -96,12 +96,12 @@ The following example will retrieve a list of servers the account has access to.
9696servers, err := svc.GetServers()
9797
9898if err != nil {
99- panic(err)
99+ panic(err)
100100}
101101
102102// Print the UUID and hostname of each server
103103for _, server := range servers.Servers {
104- fmt.Println(fmt.Sprintf("UUID: %s, hostname: %s", server.UUID, server.Hostname))
104+ fmt.Println(fmt.Sprintf("UUID: %s, hostname: %s", server.UUID, server.Hostname))
105105}
106106```
107107
@@ -112,50 +112,50 @@ Since the request for creating a new server is asynchronous, the server will rep
112112``` go
113113// Create the server
114114serverDetails , err := svc.CreateServer (&request.CreateServerRequest {
115- Zone : " fi-hel1" ,
116- Title : " My new server" ,
117- Hostname : " server.example.com" ,
118- PasswordDelivery : request.PasswordDeliveryNone ,
119- StorageDevices : []request.CreateServerStorageDevice {
120- {
121- Action: request.CreateStorageDeviceActionClone ,
122- Storage: " 01000000-0000-4000-8000-000030060200" ,
123- Title: " disk1" ,
124- Size: 30 ,
125- Tier: upcloud.StorageTierMaxIOPS ,
126- },
127- },
128- IPAddresses : []request.CreateServerIPAddress {
129- {
130- Access: upcloud.IPAddressAccessPrivate ,
131- Family: upcloud.IPAddressFamilyIPv4 ,
132- },
133- {
134- Access: upcloud.IPAddressAccessPublic ,
135- Family: upcloud.IPAddressFamilyIPv4 ,
136- },
137- {
138- Access: upcloud.IPAddressAccessPublic ,
139- Family: upcloud.IPAddressFamilyIPv6 ,
140- },
141- },
115+ Zone : " fi-hel1" ,
116+ Title : " My new server" ,
117+ Hostname : " server.example.com" ,
118+ PasswordDelivery : request.PasswordDeliveryNone ,
119+ StorageDevices : []request.CreateServerStorageDevice {
120+ {
121+ Action: request.CreateStorageDeviceActionClone ,
122+ Storage: " 01000000-0000-4000-8000-000030060200" ,
123+ Title: " disk1" ,
124+ Size: 30 ,
125+ Tier: upcloud.StorageTierMaxIOPS ,
126+ },
127+ },
128+ IPAddresses : []request.CreateServerIPAddress {
129+ {
130+ Access: upcloud.IPAddressAccessPrivate ,
131+ Family: upcloud.IPAddressFamilyIPv4 ,
132+ },
133+ {
134+ Access: upcloud.IPAddressAccessPublic ,
135+ Family: upcloud.IPAddressFamilyIPv4 ,
136+ },
137+ {
138+ Access: upcloud.IPAddressAccessPublic ,
139+ Family: upcloud.IPAddressFamilyIPv6 ,
140+ },
141+ },
142142})
143143
144144if err != nil {
145- panic (err)
145+ panic (err)
146146}
147147
148148fmt.Println (fmt.Sprintf (" Server %s with UUID %s created" , serverDetails.Title , serverDetails.UUID ))
149149
150150// Block for up to five minutes until the server has entered the "started" state
151151err = svc.WaitForServerState (&request.WaitForServerStateRequest {
152- UUID : serverDetails.UUID ,
153- DesiredState : upcloud.ServerStateStarted ,
154- Timeout : time.Minute * 5 ,
152+ UUID : serverDetails.UUID ,
153+ DesiredState : upcloud.ServerStateStarted ,
154+ Timeout : time.Minute * 5 ,
155155})
156156
157157if err != nil {
158- panic (err)
158+ panic (err)
159159}
160160
161161fmt.Println (" Server is now started" )
@@ -168,21 +168,21 @@ In this example, we assume that there is a server represented by the variable `s
168168``` go
169169// Loop through the storage devices
170170for i , storage := range serverDetails.StorageDevices {
171- // Find the first device
172- if i == 0 {
173- // Templatize the storage
174- storageDetails , err := svc.TemplatizeStorage (&request.TemplatizeStorageRequest {
175- UUID: storage.UUID ,
176- Title: " Templatized storage" ,
177- })
178-
179- if err != nil {
180- panic (err)
181- }
182-
183- fmt.Println (fmt.Sprintf (" Storage templatized as %s " , storageDetails.UUID ))
184- break
185- }
171+ // Find the first device
172+ if i == 0 {
173+ // Templatize the storage
174+ storageDetails , err := svc.TemplatizeStorage (&request.TemplatizeStorageRequest {
175+ UUID: storage.UUID ,
176+ Title: " Templatized storage" ,
177+ })
178+
179+ if err != nil {
180+ panic (err)
181+ }
182+
183+ fmt.Println (fmt.Sprintf (" Storage templatized as %s " , storageDetails.UUID ))
184+ break
185+ }
186186}
187187```
188188
@@ -192,8 +192,8 @@ In this example, we assume that there is a storage device represented by `storag
192192
193193``` go
194194backupDetails , err := svc.CreateBackup (&request.CreateBackupRequest {
195- UUID : storageDetails.UUID ,
196- Title : " Backup" ,
195+ UUID : storageDetails.UUID ,
196+ Title : " Backup" ,
197197})
198198
199199if err != nil {
@@ -209,15 +209,15 @@ In this example, we assume that there is a server represented by the variable `s
209209
210210``` go
211211firewallRule , err := svc.CreateFirewallRule (&request.CreateFirewallRuleRequest {
212- ServerUUID : serverDetails.UUID ,
213- FirewallRule : upcloud.FirewallRule {
214- Direction: upcloud.FirewallRuleDirectionIn ,
215- Action: upcloud.FirewallRuleActionAccept ,
216- Family: upcloud.IPAddressFamilyIPv4 ,
217- Protocol: upcloud.FirewallRuleProtocolTCP ,
218- Position: 1 ,
219- Comment: " Accept all TCP input on IPv4" ,
220- },
212+ ServerUUID : serverDetails.UUID ,
213+ FirewallRule : upcloud.FirewallRule {
214+ Direction: upcloud.FirewallRuleDirectionIn ,
215+ Action: upcloud.FirewallRuleActionAccept ,
216+ Family: upcloud.IPAddressFamilyIPv4 ,
217+ Protocol: upcloud.FirewallRuleProtocolTCP ,
218+ Position: 1 ,
219+ Comment: " Accept all TCP input on IPv4" ,
220+ },
221221})
222222
223223if err != nil {
0 commit comments