SDK for Go Cloud Shell Quick Start

This quick start shows you how to quickly get started running sample code with the Oracle Cloud Infrastructure SDK for Go using Cloud Shell.

This quick start shows you how to quickly get started running sample code with the Oracle Cloud Infrastructure SDK for Go using Cloud Shell. The OCI Go SDK is pre-installed in the Cloud Shell environment and included in your $GOPATH.

  1. Login to the Console.
  2. Click the Cloud Shell icon in the Console header. Note that Cloud Shell will execute commands against the region selected in the Console's Region selection menu when Cloud Shell was started.
  3. Create a file named main.go with the following code, which will list the availability domains in your tenancy:
    package main
      
    import (
        "context"
        "fmt"
     
        "github.com/oracle/oci-go-sdk/common"
        "github.com/oracle/oci-go-sdk/identity"
    )
      
    func main() {
        c, err := identity.NewIdentityClientWithConfigurationProvider(common.DefaultConfigProvider())
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
      
        // The OCID of the tenancy containing the compartment.
        tenancyID, err := common.DefaultConfigProvider().TenancyOCID()
        if err != nil {
            fmt.Println("Error:", err)
            return
            }
      
        request := identity.ListAvailabilityDomainsRequest{
            CompartmentId: &tenancyID,
        }
      
        r, err := c.ListAvailabilityDomains(context.Background(), request)
        if err != nil {
            fmt.Println("Error:", err)
            return
        }
      
        fmt.Printf("List of available domains: %v", r.Items)
        return
    }
  4. Add the following environment variable:
    export GO111MODULE=auto
  5. Run the example:
    go run main.go