sdk

package module
v0.21.8 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: Apache-2.0 Imports: 0 Imported by: 0

README

English | 简体中文

UCloud Go SDK

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

Installation

Requirements

  • Go 1.10+

Use go get

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

Note if meet network problem, you can use go proxy to speed up the downloaded, eg: use GOPROXY environment variable

export GOPROXY=https://goproxy.io

Replay the command to retry installation.

Use go mod

Add the following snippet to any code.

import _ "github.com/ucloud/ucloud-sdk-go"

And execute this commands:

go mod init
go mod tidy

Note:If using go mod and Goland IDE together, please search vgo on Settings, and enable vgo support.

Note:If using go modGOPATH, notice the go mod init/tidy can not run with GOPATH, please move out current project from GOPATH.

Use dep

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

First Using

Currently, Go SDK use PublicKey/PrivateKey as authentication method, the key can be found from:

Here is a simple example:

package main

import (
    "fmt"

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

func main() {
    cfg := ucloud.NewConfig()
    cfg.Region = "cn-bj2"

    // replace the public/private key by your own
    credential := auth.NewCredential()
    credential.PublicKey = "my_public_key"
    credential.PrivateKey = "my_private_key"

    uhostClient := uhost.NewClient(&cfg, &credential)

    req := uhostClient.NewCreateUHostInstanceRequest()
    req.Name       = ucloud.String("sdk-example-uhost")
    req.Zone       = ucloud.String("cn-bj2-05")
    req.ImageId    = ucloud.String("uimage-xxx") // you can replace the image with an available id
    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)
    } else {
        fmt.Printf("resource id of the uhost: %s\n", newUHost.UHostIds[0])
    }
}

Replace the client configuration and host image id by your custom value, then you can create a cloud host。

At this example, you had already completed a CreateUHostInstance request by UCloud Go SDK, it is covered most of feature of sdk, you can write your own script for free!

Each API call in the SDK has a detailed comment and document, You can use Editor/IDE to jump to the specific API method code to view (can also to see Go Doc), and use completion of IDE and error logging to inspect usage of SDK。

If you are interested the advanced usage about above code example, please see the documentation:

  • Configuration, Learn how to configure SDK, such as Logging, Retrying, Service endpoint(Public Cloud & Private Cloud), and etc.
  • Error Handling, Learn how to resolve the several exception types, include parameters error, business error for RetCode is not 0.
  • Type System, Learn how to validate parameters, and normalize the response of API.
  • Request Middleware, Learn how to intercept request that applied by SDK, and add common logic to the lifecycle.
  • Toolbox & Helpers, The additional helpers, such as the poll function for waiting resource state.

More Examples

Examples based on Environment

SDK provided some example based on environment, and provide resource provisioning logic . You can click the following link to view details:

Examples based on Request

UCloud UAPI product provided examples based on request, you can fill request parameters and generate example of SDK, it can be copied immediately:

  • Open UAPI
  • Select your interested API, such as CreateUHostInstance
  • Fill parameters, copy the sdk example code at right panel
  • Save code into main.go
  • Executing go mod init main
  • Executing go mod tidy
  • go run ./main.go

Note if meet network problem, you can use go proxy to speed up the downloaded, eg: use GOPROXY environment variable

export GOPROXY=https://goproxy.io

Note:If using go mod and Goland IDE together, please search vgo on Settings, and enable vgo support.

Note:If using go modGOPATH, notice the go mod init/tidy can not run with GOPATH, please move out current project from GOPATH.

Feedback & Contribution

Documentation

Overview

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

Directories

Path Synopsis
examples
internal
reverse
this helper function to reverse the sdk services to json
this helper function to reverse the sdk services to json
services/ipsecvpn
Package ipsecvpn include resources of ucloud ipsecvpn product See also - API: https://docs.ucloud.cn/api/ipsecvpn-api/index - Product: https://www.ucloud.cn/site/product/ipsecvpn.html for detail.
Package ipsecvpn include resources of ucloud ipsecvpn product See also - API: https://docs.ucloud.cn/api/ipsecvpn-api/index - Product: https://www.ucloud.cn/site/product/ipsecvpn.html for detail.
services/ufile
Package ufile include resources of ucloud ufile product See also - API: https://docs.ucloud.cn/api/ufile-api/index - Product: https://www.ucloud.cn/site/product/ufile.html for detail.
Package ufile include resources of ucloud ufile product See also - API: https://docs.ucloud.cn/api/ufile-api/index - Product: https://www.ucloud.cn/site/product/ufile.html for detail.
services/vpc
Package vpc include resources of ucloud vpc product See also - API: https://docs.ucloud.cn/api/vpc-api/index - Product: https://www.ucloud.cn/site/product/vpc.html for detail.
Package vpc include resources of ucloud vpc product See also - API: https://docs.ucloud.cn/api/vpc-api/index - Product: https://www.ucloud.cn/site/product/vpc.html for detail.
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
cube
Package cube include resources of ucloud cube product See also - API: https://docs.ucloud.cn/api/cube-api/index - Product: https://www.ucloud.cn/site/product/cube.html for detail.
Package cube include resources of ucloud cube product See also - API: https://docs.ucloud.cn/api/cube-api/index - Product: https://www.ucloud.cn/site/product/cube.html for detail.
ipsecvpn
Package ipsecvpn include resources of ucloud ipsecvpn product See also - API: https://docs.ucloud.cn/api/ipsecvpn-api/index - Product: https://www.ucloud.cn/site/product/ipsecvpn.html for detail.
Package ipsecvpn include resources of ucloud ipsecvpn product See also - API: https://docs.ucloud.cn/api/ipsecvpn-api/index - Product: https://www.ucloud.cn/site/product/ipsecvpn.html for detail.
isms
Package isms include resources of ucloud isms product See also - API: https://docs.ucloud.cn/api/isms-api/index - Product: https://www.ucloud.cn/site/product/isms.html for detail.
Package isms include resources of ucloud isms product See also - API: https://docs.ucloud.cn/api/isms-api/index - Product: https://www.ucloud.cn/site/product/isms.html for detail.
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.
ubill
Package ubill include resources of ucloud ubill product See also - API: https://docs.ucloud.cn/api/ubill-api/index - Product: https://www.ucloud.cn/site/product/ubill.html for detail.
Package ubill include resources of ucloud ubill product See also - API: https://docs.ucloud.cn/api/ubill-api/index - Product: https://www.ucloud.cn/site/product/ubill.html for detail.
ucdn
Package ucdn include resources of ucloud ucdn product See also - API: https://docs.ucloud.cn/api/ucdn-api/index - Product: https://www.ucloud.cn/site/product/ucdn.html for detail.
Package ucdn include resources of ucloud ucdn product See also - API: https://docs.ucloud.cn/api/ucdn-api/index - Product: https://www.ucloud.cn/site/product/ucdn.html for detail.
ucloudstack
Package ucloudstack include resources of ucloud ucloudstack product See also - API: https://docs.ucloud.cn/api/ucloudstack-api/index - Product: https://www.ucloud.cn/site/product/ucloudstack.html for detail.
Package ucloudstack include resources of ucloud ucloudstack product See also - API: https://docs.ucloud.cn/api/ucloudstack-api/index - Product: https://www.ucloud.cn/site/product/ucloudstack.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.
uddb
Package uddb include resources of ucloud uddb product See also - API: https://docs.ucloud.cn/api/uddb-api/index - Product: https://www.ucloud.cn/site/product/uddb.html for detail.
Package uddb include resources of ucloud uddb product See also - API: https://docs.ucloud.cn/api/uddb-api/index - Product: https://www.ucloud.cn/site/product/uddb.html for detail.
udisk
Package udisk include resources of ucloud udisk 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 udisk 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.
udts
Package udts include resources of ucloud udts product See also - API: https://docs.ucloud.cn/api/udts-api/index - Product: https://www.ucloud.cn/site/product/udts.html for detail.
Package udts include resources of ucloud udts product See also - API: https://docs.ucloud.cn/api/udts-api/index - Product: https://www.ucloud.cn/site/product/udts.html for detail.
uec
Package uec include resources of ucloud uec product See also - API: https://docs.ucloud.cn/api/uec-api/index - Product: https://www.ucloud.cn/site/product/uec.html for detail.
Package uec include resources of ucloud uec product See also - API: https://docs.ucloud.cn/api/uec-api/index - Product: https://www.ucloud.cn/site/product/uec.html for detail.
ufile
Package ufile include resources of ucloud ufile product See also - API: https://docs.ucloud.cn/api/ufile-api/index - Product: https://www.ucloud.cn/site/product/ufile.html for detail.
Package ufile include resources of ucloud ufile product See also - API: https://docs.ucloud.cn/api/ufile-api/index - Product: https://www.ucloud.cn/site/product/ufile.html for detail.
ufs
Package ufs include resources of ucloud ufs product See also - API: https://docs.ucloud.cn/api/ufs-api/index - Product: https://www.ucloud.cn/site/product/ufs.html for detail.
Package ufs include resources of ucloud ufs product See also - API: https://docs.ucloud.cn/api/ufs-api/index - Product: https://www.ucloud.cn/site/product/ufs.html for detail.
ugn
Package ugn include resources of ucloud ugn product See also - API: https://docs.ucloud.cn/api/ugn-api/index - Product: https://www.ucloud.cn/site/product/ugn.html for detail.
Package ugn include resources of ucloud ugn product See also - API: https://docs.ucloud.cn/api/ugn-api/index - Product: https://www.ucloud.cn/site/product/ugn.html for detail.
uhost
Package uhost include resources of ucloud uhost 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 uhost product See also - API: https://docs.ucloud.cn/api/uhost-api/index - Product: https://www.ucloud.cn/site/product/uhost.html for detail.
uk8s
Package uk8s include resources of ucloud uk8s product See also - API: https://docs.ucloud.cn/api/uk8s-api/index - Product: https://www.ucloud.cn/site/product/uk8s.html for detail.
Package uk8s include resources of ucloud uk8s product See also - API: https://docs.ucloud.cn/api/uk8s-api/index - Product: https://www.ucloud.cn/site/product/uk8s.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.
umedia
Package umedia include resources of ucloud umedia product See also - API: https://docs.ucloud.cn/api/umedia-api/index - Product: https://www.ucloud.cn/site/product/umedia.html for detail.
Package umedia include resources of ucloud umedia product See also - API: https://docs.ucloud.cn/api/umedia-api/index - Product: https://www.ucloud.cn/site/product/umedia.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 uphost 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 uphost product See also - API: https://docs.ucloud.cn/api/uphost-api/index - Product: https://www.ucloud.cn/site/product/uphost.html for detail.
urocketmq
Package urocketmq include resources of ucloud urocketmq product See also - API: https://docs.ucloud.cn/api/urocketmq-api/index - Product: https://www.ucloud.cn/site/product/urocketmq.html for detail.
Package urocketmq include resources of ucloud urocketmq product See also - API: https://docs.ucloud.cn/api/urocketmq-api/index - Product: https://www.ucloud.cn/site/product/urocketmq.html for detail.
usms
Package usms include resources of ucloud usms product See also - API: https://docs.ucloud.cn/api/usms-api/index - Product: https://www.ucloud.cn/site/product/usms.html for detail.
Package usms include resources of ucloud usms product See also - API: https://docs.ucloud.cn/api/usms-api/index - Product: https://www.ucloud.cn/site/product/usms.html for detail.
vpc
Package vpc include resources of ucloud vpc product See also - API: https://docs.ucloud.cn/api/vpc-api/index - Product: https://www.ucloud.cn/site/product/vpc.html for detail.
Package vpc include resources of ucloud vpc product See also - API: https://docs.ucloud.cn/api/vpc-api/index - Product: https://www.ucloud.cn/site/product/vpc.html for detail.
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

Jump to

Keyboard shortcuts

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