UCloud SDK for Golang
See the codeEnglish | 简体中文
go getgo 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.
go modAdd 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 mod 和 GOPATH, notice the go mod init/tidy can not run with GOPATH, please move out current project from GOPATH.
depdep ensure -add github.com/ucloud/ucloud-sdk-go
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:
SDK provided some example based on environment, and provide resource provisioning logic . You can click the following link to view details:
UCloud UAPI product provided examples based on request, you can fill request parameters and generate example of SDK, it can be copied immediately:
main.gogo mod init maingo mod tidygo run ./main.goNote 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 mod 和 GOPATH, notice the go mod init/tidy can not run with GOPATH, please move out current project from GOPATH.
Overall
Maintained
Code review
Go module
Latest release
Releases this year
UCloud SDK for Golang
See the codeEnglish | 简体中文
go getgo 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.
go modAdd 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 mod 和 GOPATH, notice the go mod init/tidy can not run with GOPATH, please move out current project from GOPATH.
depdep ensure -add github.com/ucloud/ucloud-sdk-go
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:
SDK provided some example based on environment, and provide resource provisioning logic . You can click the following link to view details:
UCloud UAPI product provided examples based on request, you can fill request parameters and generate example of SDK, it can be copied immediately:
main.gogo mod init maingo mod tidygo run ./main.goNote 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 mod 和 GOPATH, notice the go mod init/tidy can not run with GOPATH, please move out current project from GOPATH.
Overall
Maintained
Code review
Go module
Latest release
Releases this year