• CLI

sdk
  1. Help Center
  2. CLI
  3. Developer Guide
  4. SDK
  5. Go
  6. Getting Started

Getting Started

Prerequisites

  1. You have obtained required API documents.

    Log in to the following website to obtain the API documents:

    https://docs.otc.t-systems.com/

    With these documents, you can obtain the API parameters supported by the cloud platform.

  2. You have obtained the official Gophercloud documents.

    Log in to the following website to obtain official Gophercloud documents:

    http://gophercloud.io/docs/

    It is important for you to learn how to use Gophercloud.

  3. You have obtained a cloud platform account and provisioned all required services.
  4. Go 1.9.1 is recommended.
  5. You have understood the source code of the Gophercloud projects. For details, visit the following website:

    https://github.com/gophercloud

SDK Acquisition and Installation

Before the installation, ensure that the GOPATH environment variable points to the target directory of Gophercloud to be installed.

mkdir $HOME/go
export GOPATH=$HOME/go

To prevent the dependency relationship from changing, you are advised to use the dependency solution, for example, godep. After this solution is used, you can install Gophercloud by using the following method:

go get github.com/gophercloud/gophercloud
# Edit your code to import relevant packages from "github.com/gophercloud/gophercloud"
godep save ./...

This method installs the required source files in a directory. Your source files will be referenced when you use the godep go command.

How to Use

Before making a call to the SDK to access service APIs, you need to configure parameters and complete authentication.

import (
  "github.com/gophercloud/gophercloud"
  "github.com/gophercloud/gophercloud/openstack"
  "github.com/gophercloud/gophercloud/openstack/utils"
)

// Pass in the values yourself
opts := gophercloud.AuthOptions{
  IdentityEndpoint: "https://iam.example.com/v3",
  Username: "{username}",
  Password: "{password}",
  DomainName: "{domainname}",
  TenantID: "{tenantid}",
}

provider, err := openstack.AuthenticatedClient(opts)
  • example in the preceding code is in the Region.Cloud platform domain name format. For details about the parameters, see here.
  • ProviderClient is the top-level client required by all OpenStack services. The client contains all authentication details, such as the URL and token ID. After the authentication, the compiled Go code can access the APIs.
  • The Service Client of a service is required if you need to access this service. For details, see the related chapter about this service in this document.