|
| 1 | +[](https://travis-ci.com/IBM/vpc-go-sdk) |
| 2 | +[](https://opensource.org/licenses/Apache-2.0) |
| 3 | + |
| 4 | +[](https://github.com/semantic-release/semantic-release) |
| 5 | + |
| 6 | +# IBM Cloud VPC Go SDK Version 0.16.0 |
| 7 | +Go client library to interact with the various [IBM Cloud VPC Services APIs](https://cloud.ibm.com/apidocs?category=vpc). |
| 8 | + |
| 9 | +**Note:** Given the current version of all VPC SDKs across supported languages and the current VPC API specification, we retracted the vpc-go-sdk version 1.x to version v0.6.0, which had the same features as v1.0.1. |
| 10 | +Consider using v0.16.0 from now on. Refrain from using commands like `go get -u ..` and `go get ..@latest` as you will not get the latest release. |
| 11 | + |
| 12 | +This SDK uses [Semantic Versioning](https://semver.org), and as such there may be backward-incompatible changes for any new `0.y.z` version. |
| 13 | +## Table of Contents |
| 14 | +<!-- |
| 15 | + The TOC below is generated using the `markdown-toc` node package. |
| 16 | +
|
| 17 | + https://github.com/jonschlinkert/markdown-toc |
| 18 | +
|
| 19 | + You should regenerate the TOC after making changes to this file. |
| 20 | +
|
| 21 | + npx markdown-toc -i README.md |
| 22 | + --> |
| 23 | + |
| 24 | +<!-- toc --> |
| 25 | + |
| 26 | +- [Overview](#overview) |
| 27 | +- [Prerequisites](#prerequisites) |
| 28 | +- [Installation](#installation) |
| 29 | + + [`go get` command](#go-get-command) |
| 30 | + + [Go modules](#go-modules) |
| 31 | + + [`dep` dependency manager](#dep-dependency-manager) |
| 32 | +- [Using the SDK](#using-the-sdk) |
| 33 | +- [Setting up VPC service](#setting-up-vpc-service) |
| 34 | +- [Questions](#questions) |
| 35 | +- [Issues](#issues) |
| 36 | +- [Open source @ IBM](#open-source--ibm) |
| 37 | +- [Contributing](#contributing) |
| 38 | +- [License](#license) |
| 39 | + |
| 40 | +<!-- tocstop --> |
| 41 | + |
| 42 | +## Overview |
| 43 | + |
| 44 | +The IBM Cloud VPC Go SDK allows developers to programmatically interact with the following IBM Cloud services: |
| 45 | + |
| 46 | +Service Name | Package name |
| 47 | +--- | --- |
| 48 | +[VPC](https://cloud.ibm.com/apidocs/vpc) | vpcv1 |
| 49 | + |
| 50 | +## Prerequisites |
| 51 | + |
| 52 | +[ibm-cloud-onboarding]: https://cloud.ibm.com/registration |
| 53 | + |
| 54 | +* An [IBM Cloud][ibm-cloud-onboarding] account. |
| 55 | +* An IAM API key to allow the SDK to access your account. Create an apikey [here](https://cloud.ibm.com/iam/apikeys). |
| 56 | +* Go version 1.12 or above. |
| 57 | + |
| 58 | +## Installation |
| 59 | +There are a few different ways to download and install the VPC Go SDK services for use by your |
| 60 | +Go application: |
| 61 | + |
| 62 | +#### `go get` command |
| 63 | +Use this command to download and install the VPC Go SDK service to allow your Go application to |
| 64 | +use it: |
| 65 | + |
| 66 | +``` |
| 67 | +go get github.com/IBM/[email protected] |
| 68 | +``` |
| 69 | + |
| 70 | + |
| 71 | +#### Go modules |
| 72 | +If your application is using Go modules, you can add a suitable import to your |
| 73 | +Go application, like this: |
| 74 | + |
| 75 | + |
| 76 | +```go |
| 77 | +import ( |
| 78 | + "github.com/IBM/vpc-go-sdk/vpcv1" |
| 79 | +) |
| 80 | +``` |
| 81 | + |
| 82 | +Then run `go mod tidy` to download and install the new dependency and update your Go application's |
| 83 | +`go.mod` file. |
| 84 | + |
| 85 | + |
| 86 | +#### `dep` dependency manager |
| 87 | +If your application is using the `dep` dependency management tool, you can add a dependency |
| 88 | +to your `Gopkg.toml` file. Here is an example: |
| 89 | + |
| 90 | +``` |
| 91 | +[[constraint]] |
| 92 | + name = "github.com/IBM/vpc-go-sdk/" |
| 93 | + version = "0.16.0" |
| 94 | +``` |
| 95 | + |
| 96 | +Then run `dep ensure`. |
| 97 | + |
| 98 | +## Using the SDK |
| 99 | +For general SDK usage information, see the [IBM Cloud SDK Common README](https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md) |
| 100 | + |
| 101 | +## Setting up VPC service |
| 102 | + |
| 103 | +A quick example to get you up and running with VPC Go SDK service in Dallas (us-south) region. |
| 104 | + |
| 105 | +For other regions, see [API Endpoints for VPC](https://cloud.ibm.com/apidocs/vpc#api-endpoint) and update the `URL` variable accordingly. |
| 106 | + |
| 107 | + |
| 108 | +Refer to the [VPC Release Notes](https://cloud.ibm.com/docs/vpc?topic=vpc-release-notes) to find out latest version release. |
| 109 | + |
| 110 | +```go |
| 111 | +package main |
| 112 | + |
| 113 | +import ( |
| 114 | + "log" |
| 115 | + "os" |
| 116 | + |
| 117 | + "github.com/IBM/go-sdk-core/v4/core" |
| 118 | + "github.com/IBM/vpc-go-sdk/vpcv1" |
| 119 | +) |
| 120 | + |
| 121 | +func main() { |
| 122 | + apiKey := os.Getenv("IBMCLOUD_API_KEY") |
| 123 | + if apiKey == "" { |
| 124 | + log.Fatal("No API key set") |
| 125 | + } |
| 126 | + |
| 127 | + // Instantiate the service with an API key based IAM authenticator |
| 128 | + vpcService, err := vpcv1.NewVpcV1(&vpcv1.VpcV1Options{ |
| 129 | + Authenticator: &core.IamAuthenticator{ |
| 130 | + ApiKey: apiKey, |
| 131 | + }, |
| 132 | + }) |
| 133 | + if err != nil { |
| 134 | + log.Fatal("Error creating VPC Service.") |
| 135 | + } |
| 136 | + |
| 137 | + // Retrieve the list of regions for your account. |
| 138 | + regions, detailedResponse, err := vpcService.ListRegions(&vpcv1.ListRegionsOptions{}) |
| 139 | + if err != nil { |
| 140 | + log.Fatalf("Failed to list the regions: %v and the response is: %s", err, detailedResponse) |
| 141 | + } |
| 142 | + log.Printf("Regions: %#v", regions) |
| 143 | + |
| 144 | + // Retrieve the list of vpcs for your account. |
| 145 | + vpcs, detailedResponse, err := vpcService.ListVpcs(&vpcv1.ListVpcsOptions{}) |
| 146 | + if err != nil { |
| 147 | + log.Fatalf("Failed to list vpcs: %v and the response is: %s", err, detailedResponse) |
| 148 | + } |
| 149 | + log.Printf("VPCs: %#v", vpcs) |
| 150 | + |
| 151 | + // Create an SSH key |
| 152 | + sshKeyOptions := &vpcv1.CreateKeyOptions{ |
| 153 | + Name: core.StringPtr("my-ssh-key"), |
| 154 | + } |
| 155 | + // Setters also exist to set fields are the struct has been created |
| 156 | + sshKeyOptions.SetPublicKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsnrSAe8eBi8mS576Z96UtYgUzDR9Sbw/s1ELxsa1KUK82JQ0Ejmz31N6sHyiT/l5533JgGL6rKamLFziMY2VX2bdyuF5YzyHhmapT+e21kuTatB50UsXzxlYEWpCmFdnd4LhwFn6AycJWOV0k3e0ePpVxgHc+pVfE89322cbmfuppeHxvxc+KSzQNYC59A+A2vhucbuWppyL3EIF4YgLwOr5iDISm1IR0+EEL3yJQIG4M2WKu526anI85QBcIWyFwQXOpdcX2eZRcd6WW2EgAM3fIOaezkm0CFrsz8rQ0MPYZI4BS2CWwg5d4Bj7SU2sjXz62gfQkQGTYWSqhizVb root@localhost") |
| 157 | + key, detailedResponse, err := vpcService.CreateKey(sshKeyOptions) |
| 158 | + if err != nil { |
| 159 | + log.Fatalf("Failed to create the ssh key: %v and the response is: %s", err, detailedResponse) |
| 160 | + } |
| 161 | + log.Printf("SSH key: %s created with ID: %s", *key.Name, *key.ID) |
| 162 | + |
| 163 | + // Delete SSH key |
| 164 | + detailedResponse, err = vpcService.DeleteKey(&vpcv1.DeleteKeyOptions{ |
| 165 | + ID: key.ID, |
| 166 | + }) |
| 167 | + if err != nil { |
| 168 | + log.Fatalf("Failed to delete the ssh key: %v and the response is: %s", err, detailedResponse) |
| 169 | + } |
| 170 | + |
| 171 | + log.Printf("SSH key: %s deleted with ID: %s", *key.Name, *key.ID) |
| 172 | +} |
| 173 | +``` |
| 174 | + |
| 175 | +## Questions |
| 176 | + |
| 177 | +If you have difficulties using this SDK or you have a question about the IBM Cloud services, |
| 178 | +ask a question at |
| 179 | +[Stack Overflow](http://stackoverflow.com/questions/ask?tags=ibm-cloud). |
| 180 | + |
| 181 | +## Issues |
| 182 | +If you encounter an issue with the project, you are welcome to submit a |
| 183 | +[bug report](<github-repo-url>/issues). |
| 184 | +Before you create a new issue, search for similar issues. It's possible that someone has already reported the problem. |
| 185 | + |
| 186 | +## Open source @ IBM |
| 187 | +Find more open source projects on the [IBM Github Page](http://ibm.github.io/). |
| 188 | + |
| 189 | +## Contributing |
| 190 | +See [CONTRIBUTING](CONTRIBUTING.md). |
| 191 | + |
| 192 | +## License |
| 193 | + |
| 194 | +This SDK project is released under the Apache 2.0 license. |
| 195 | +The license's full text can be found in [LICENSE](LICENSE). |
0 commit comments