1- # UpCloud Go SDK
1+ # UpCloud Go API client library
22
3- [ ![ Build Status] ( https://travis-ci.org/UpCloudLtd/upcloud-go-sdk .svg?branch=master )] ( https://travis-ci.org/UpCloudLtd/upcloud-go-sdk )
4- [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/UpCloudLtd/upcloud-go-sdk )] ( https://goreportcard.com/report/github.com/UpCloudLtd/upcloud-go-sdk )
5- [ ![ GoDoc] ( https://godoc.org/github.com/UpCloudLtd/upcloud-go-sdk ?status.svg )] ( https://godoc.org/github.com/UpCloudLtd/upcloud-go-sdk )
3+ [ ![ Build Status] ( https://travis-ci.org/UpCloudLtd/upcloud-go-api .svg?branch=master )] ( https://travis-ci.org/UpCloudLtd/upcloud-go-api )
4+ [ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/UpCloudLtd/upcloud-go-api )] ( https://goreportcard.com/report/github.com/UpCloudLtd/upcloud-go-api )
5+ [ ![ GoDoc] ( https://godoc.org/github.com/UpCloudLtd/upcloud-go-api ?status.svg )] ( https://godoc.org/github.com/UpCloudLtd/upcloud-go-api )
66
7- This is the SDK for interfacing with UpCloud's API using the Go programming language. The features in the development kit allow easy application creation and simplify UpCloud API integration when using Go.
7+ This is the official client for interfacing with UpCloud's API using the Go programming language. The features allows for easy and quick development and integration when using Go.
88
99## Installation and requirements
1010
11- You'll need Go 1.7 or higher to use the SDK . You can use the following command to retrieve the SDK :
11+ You'll need Go 1.7 or higher to use the client . You can use the following command to retrieve the client :
1212
1313```
14- go get github.com/UpCloudLtd/upcloud-go-sdk
14+ go get github.com/UpCloudLtd/upcloud-go-api
1515```
1616
1717## Usage
1818
19- The general usage of the SDK adheres to the following pattern:
19+ The general usage of the client adheres to the following pattern:
2020
2121* Authenticate by creating a ` client.Client `
2222* Create a ` service.Service ` by passing the newly created ` client ` object to it
2323* Interface with the API using the various methods of the ` service ` object. Methods that take parameters wrap them in request objects.
2424
2525We recommend setting up a separate subaccount for API usage to allow better access control and security. You can find out more about creating subaccounts at the following support article for [ Server Tags and Group Accounts] ( https://www.upcloud.com/support/server-tags-and-group-accounts/ ) . We strongly recommend limiting the connections to a specific address or address range for security purposes.
2626
27- The examples here only deal with how to use the SDK itself. For information on how to use the API in general, please consult the [ UpCloud API documentation] ( https://www.upcloud.com/api/ ) .
27+ The examples here only deal with how to use the client itself. For information on how to use the API in general, please consult the [ UpCloud API documentation] ( https://www.upcloud.com/api/ ) .
2828
2929### Creating the client and the service
3030
@@ -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 {
@@ -242,16 +242,16 @@ it returns. Import the collection into Postman, then create an environment conta
242242To be able to run the test suite you'll need to export the following environment variables with their corresponding
243243values:
244244
245- * ` UPCLOUD_GO_SDK_TEST_USER ` (the API username)
246- * ` UPCLOUD_GO_SDK_TEST_PASSWORD ` (the API password)
247- * ` UPCLOUD_GO_SDK_TEST_DELETE_RESOURCES ` (either ` yes ` or ` no ` )
245+ * ` UPCLOUD_GO_API_TEST_USER ` (the API username)
246+ * ` UPCLOUD_GO_API_TEST_PASSWORD ` (the API password)
247+ * ` UPCLOUD_GO_API_TEST_DELETE_RESOURCES ` (either ` yes ` or ` no ` )
248248
249- To run the test suite, run ` go test ./... -v -parallel 8 ` . If ` UPCLOUD_GO_SDK_TEST_DELETE_RESOURCES ` is set to ` yes ` ,
249+ To run the test suite, run ` go test ./... -v -parallel 8 ` . If ` UPCLOUD_GO_API_TEST_DELETE_RESOURCES ` is set to ` yes ` ,
250250all resources will be stopped and/or deleted after the test suite has run. Be careful which account you use for
251251testing so you don't accidentally delete or your production resources!
252252
253253You can skip running the integration tests and just run the unit tests by passing ` -short ` to the test command.
254254
255255## License
256256
257- This SDK is distributed under the [ MIT License] ( https://opensource.org/licenses/MIT ) , see LICENSE.txt for more information.
257+ This client is distributed under the [ MIT License] ( https://opensource.org/licenses/MIT ) , see LICENSE.txt for more information.
0 commit comments