Package management

更新时间:
复制 MD 格式

Alibaba Cloud SDK for Go uses Go modules for dependency management.

For example, if you have a Go project folder named goprojects, run the following commands in its root directory:

# Initialize a new go.mod file in the current directory to define the module name. The module name is usually the path of the repository URL. For example, the domain name is example.com and the project is goproject.
go mod init example.com/goproject

# Download the dependencies listed in the go.mod file. This command pulls the dependencies and places them in the $GOPATH/pkg/mod directory.
go mod download

# Clean up and synchronize the go.mod and go.sum files to ensure the dependency list is accurate.
go mod tidy

# go get: Downloads and installs a specified package and its dependencies.
# Add a version number after the package name, such as "@v1.0".
# For specific version numbers, see https://github.com/aliyun/alibaba-cloud-sdk-go/releases
go get [packages]

FAQ

  • Running the go get command returns the error: "A connection attempt failed because the connected party did not properly respond after a period of time, or connection failed because connected host has failed to respond."

    The default Go proxy is GOPROXY=https://proxy.golang.org,direct. This proxy is inaccessible from mainland China because it is an external address. You can change the proxy by running the go env -w GOPROXY='https://goproxy.cn,direct' command. Then, run the go get command again to download the package.