sdk

package module
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2019 License: Apache-2.0 Imports: 0 Imported by: 0

README

UCloud Go SDK

GitHub (pre-)release Go Report Card Codecov Build Status SonarQube GoDoc GitHub

UCloud SDK is a Go client library for accessing the UCloud API.

This client can run on Linux, macOS and Windows. It requires Golang 1.10.x and above.

Install

via source

go get github.com/ucloud/ucloud-sdk-go

via dep

dep ensure -add github.com/ucloud/ucloud-sdk-go

Usage

import (
   "github.com/ucloud/ucloud-sdk-go"
)

Create a new UCloud client of each service to access the different parts of the UCloud API.

Authentication

Currently, user public key & private key is the only method of authenticating with the API. You could get your keys here: Key Generation

You can then use your keys to create a new client of uhost service:

package main

import (
    "github.com/ucloud/ucloud-sdk-go/ucloud"
    "github.com/ucloud/ucloud-sdk-go/ucloud/auth"
    "github.com/ucloud/ucloud-sdk-go/services/uhost"
)

func loadConfig() (*ucloud.Config, *auth.Credential) {
    cfg := ucloud.NewConfig()

    credential := auth.NewCredential()
    credential.PrivateKey ="my_privatekey"
    credential.PublicKey = "my_publickey"

    return &cfg, &credential
}

func main() {
    cfg, credential := loadConfig()
    uhostClient := uhost.NewClient(cfg, credential)
}

Quick Start

To create a new uhost:

// build Request
req := uhostClient.NewCreateUHostInstanceRequest()
req.Name       = ucloud.String("sdk-example-uhost")
req.Zone       = ucloud.String("cn-bj2-05")
req.ImageId    = ucloud.String("uimage-ixczxu")
req.LoginMode  = ucloud.String("Password")
req.Password   = ucloud.String("my_uhost_password")
req.ChargeType = ucloud.String("Dynamic")
req.CPU        = ucloud.Int(1)
req.Memory     = ucloud.Int(1024)
req.Tag        = ucloud.String("sdk-example")

// send request
newUHost,err := uhostClient.CreateUHostInstance(req)
if err != nil {
    fmt.Printf("something bad happened: %s\n", err)
}

fmt.Printf("resource id of the uhost: %s\n", newUHost.UHostIds[0])

Note

UHost created above cannot be accessed via Internet unless an EIP is created and bind to the UHost.

Complex structure in query

You can also set array as query, such as:

req.UHostIds = []string{"uhost-xxx", "uhost-yyy"}

will encoded as UHostIds.0=uhost-xxx&UHostIds.1=uhost-yyy

dataDisk := uhost.UHostDisk{
    Size: ucloud.Int(20),
    Type: ucloud.String("CLOUD_NORMAL"),
    IsBoot: ucloud.Bool(false),
}
req.Disks = []uhost.UHostDisk{dataDisk}

will encoded as Disks.0.Size=20&Disks.0.Type=CLOUD_NORMAL&Disks.0.IsBoot=false

Docs

Feedback & Contribution

Documentation

Overview

Package sdk is a toolkit for developer to create custom infrastructure via ucloud open api.

Directories

Path Synopsis
examples
internal
private
protocol/http
Package http is an implementation of http protocol
Package http is an implementation of http protocol
services/ulb
Package ulb include resources of ucloud ulb product See also - API: https://docs.ucloud.cn/api/ulb-api/index - Product: https://www.ucloud.cn/site/product/ulb.html for detail.
Package ulb include resources of ucloud ulb product See also - API: https://docs.ucloud.cn/api/ulb-api/index - Product: https://www.ucloud.cn/site/product/ulb.html for detail.
services/vpc
Package vpc include resources of ucloud vpc 2.0 product
Package vpc include resources of ucloud vpc 2.0 product
utils
Package utils is the utilities to process internal data of sdk
Package utils is the utilities to process internal data of sdk
services
pathx
Package pathx include resources of ucloud pathx product See also - API: https://docs.ucloud.cn/api/pathx-api/index - Product: https://www.ucloud.cn/site/product/pathx.html for detail.
Package pathx include resources of ucloud pathx product See also - API: https://docs.ucloud.cn/api/pathx-api/index - Product: https://www.ucloud.cn/site/product/pathx.html for detail.
stepflow
Package stepflow include resources of ucloud stepflow product See also - API: https://docs.ucloud.cn/api/stepflow-api/index - Product: https://www.ucloud.cn/site/product/stepflow.html for detail.
Package stepflow include resources of ucloud stepflow product See also - API: https://docs.ucloud.cn/api/stepflow-api/index - Product: https://www.ucloud.cn/site/product/stepflow.html for detail.
uaccount
Package uaccount include resources of ucloud uaccount product See also - API: https://docs.ucloud.cn/api/uaccount-api/index - Product: https://www.ucloud.cn/site/product/uaccount.html for detail.
Package uaccount include resources of ucloud uaccount product See also - API: https://docs.ucloud.cn/api/uaccount-api/index - Product: https://www.ucloud.cn/site/product/uaccount.html for detail.
udb
Package udb include resources of ucloud udb product See also - API: https://docs.ucloud.cn/api/udb-api/index - Product: https://www.ucloud.cn/site/product/udb.html for detail.
Package udb include resources of ucloud udb product See also - API: https://docs.ucloud.cn/api/udb-api/index - Product: https://www.ucloud.cn/site/product/udb.html for detail.
udisk
Package udisk include resources of ucloud disk product See also - API: https://docs.ucloud.cn/api/udisk-api/index - Product: https://www.ucloud.cn/site/product/udisk.html for detail.
Package udisk include resources of ucloud disk product See also - API: https://docs.ucloud.cn/api/udisk-api/index - Product: https://www.ucloud.cn/site/product/udisk.html for detail.
udpn
Package udpn include resources of ucloud udpn product See also - API: https://docs.ucloud.cn/api/udpn-api/index - Product: https://www.ucloud.cn/site/product/udpn.html for detail.
Package udpn include resources of ucloud udpn product See also - API: https://docs.ucloud.cn/api/udpn-api/index - Product: https://www.ucloud.cn/site/product/udpn.html for detail.
uhost
Package uhost include resources of ucloud host product See also - API: https://docs.ucloud.cn/api/uhost-api/index - Product: https://www.ucloud.cn/site/product/uhost.html for detail.
Package uhost include resources of ucloud host product See also - API: https://docs.ucloud.cn/api/uhost-api/index - Product: https://www.ucloud.cn/site/product/uhost.html for detail.
ulb
Package ulb include resources of ucloud ulb product See also - API: https://docs.ucloud.cn/api/ulb-api/index - Product: https://www.ucloud.cn/site/product/ulb.html for detail.
Package ulb include resources of ucloud ulb product See also - API: https://docs.ucloud.cn/api/ulb-api/index - Product: https://www.ucloud.cn/site/product/ulb.html for detail.
umem
Package umem include resources of ucloud umem product See also - API: https://docs.ucloud.cn/api/umem-api/index - Product: https://www.ucloud.cn/site/product/umem.html for detail.
Package umem include resources of ucloud umem product See also - API: https://docs.ucloud.cn/api/umem-api/index - Product: https://www.ucloud.cn/site/product/umem.html for detail.
unet
Package unet include resources of ucloud unet product See also - API: https://docs.ucloud.cn/api/unet-api/index - Product: https://www.ucloud.cn/site/product/unet.html for detail.
Package unet include resources of ucloud unet product See also - API: https://docs.ucloud.cn/api/unet-api/index - Product: https://www.ucloud.cn/site/product/unet.html for detail.
uphost
Package uphost include resources of ucloud host product See also - API: https://docs.ucloud.cn/api/uphost-api/index - Product: https://www.ucloud.cn/site/product/uphost.html for detail.
Package uphost include resources of ucloud host product See also - API: https://docs.ucloud.cn/api/uphost-api/index - Product: https://www.ucloud.cn/site/product/uphost.html for detail.
vpc
Package vpc include resources of ucloud vpc 2.0 product
Package vpc include resources of ucloud vpc 2.0 product
Package ucloud is a package of utilities to setup ucloud sdk and improve using experience
Package ucloud is a package of utilities to setup ucloud sdk and improve using experience
auth
Package auth is the credential utilities of sdk
Package auth is the credential utilities of sdk
error
Package uerr is the error definition of service and sdk
Package uerr is the error definition of service and sdk
helpers/waiter
Package waiter is a helper package use for waiting remote state is transformed into target state.
Package waiter is a helper package use for waiting remote state is transformed into target state.
log
Package log is the log utilities of sdk
Package log is the log utilities of sdk
request
Package request is the request of service
Package request is the request of service
response
Package response is the response of service
Package response is the response of service
version
Package version is the version of sdk
Package version is the version of sdk

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL