OSS SDK for Go allows you to programmatically manage resources in Object Storage Service (OSS). For example, you can manage buckets, upload objects, download objects, and process images. This topic describes how to install OSS SDK for Go.
Environment preparations
Environment requirements
OSS SDK for Go 1.13 or later is recommended.
For more information about how to download and install the environment for OSS SDK for Go, visit Installing Go from source.
If OSS SDK for Go 1.13 or later is used, the module mode is enabled by default to manage package dependencies. You do not need to manually specify the
GOPATH
system variable.If OSS SDK for Go 1.12 or earlier is used, you need to specify the
GOPATH
system variable and point it to your code directory. For more information about the GOPATH system variable, run thego help gopath
command.
Check the version of OSS SDK for Go
Run the
go version
command to view the version of Go.
Download OSS SDK for Go
Install OSS SDK for Go
Go mod
Add the following dependencies to the go.mod
file. In the following example, OSS SDK for Go 3.0.2 is used. If you use another version, use the number of the version.
require (
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
)
Source code
go get github.com/aliyun/aliyun-oss-go-sdk/oss
No messages appear during the installation. The installation process requires a few minutes to complete. If the installation fails, run the preceding command again.
Verify whether OSS SDK for Go is installed
Run the following code to query the version of OSS SDK for Go:
package main
import (
"fmt"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
fmt.Println("OSS Go SDK Version: ", oss.Version)
}
What to do next
After you install OSS SDK for Go, you need to configure access credentials. For more information, see Configure access credentials.