You must have an active Alibaba Cloud OSS account. You must create an AccessKey ID and an AccessKey Secret. Go to Alibaba Cloud AccessKey Management to create an AccessKey.
To activate Alibaba Cloud OSS or to have more information about Alibaba Cloud OSS, log on to OSS product homepage to learn more.
If you have not installed Go’s compiling and running environment, see Install Go to download and install the compiling and running environment.
Download and install Go’s compiling and running environment. After Go is installed, set the GOPATH variable correctly. For more information about GOPATH, run the
go help gopathcommand.
go get github.com/aliyun/aliyun-oss-go-sdk/oss command to install OSS Go SDK.
For Windows, run the installation command in cmd. For Linux/Mac, run the command on the terminal.
No messages are printed to the interface during installation. Be patient. In case of installation time-out, run
Download the code file. Download the OSS Go SDK code from GitHub.
Modify the configuration items of endpoint, AccessKeyId, AccessKeySecret, and BucketName in
go run sample.go.
The example code of the Go SDK is under the sample directory. Address: GitHub.
The example includes the following content:
|Example file||Example content|
|new_bucket.go||Demonstrates how to initialize the client and bucket|
|put_object.go||Demonstrates simple upload and resumable upload usage|
|append_object.go||Demonstrates append upload usage|
|get_object.go||Demonstrates stream download, download by range and resumable download usage|
|delete_object.go||Demonstrates methods to delete a single object and delete objects by batch|
|copy_object.go||Demonstrates object copy and resumable copy usage|
|list_objects.go||Demonstrates object listing usage including listing by default parameters and listing by specified parameters|
|object_meta.go||Demonstrates how to set and read object metadata (Object Meta)|
|object_acl.go||Demonstrates how to set and read object ACL (Object ACL)|
|cname_sample.go||Demonstrates CNAME usage|
|create_bucket.go||Demonstrates how to create a bucket|
|list_buckets.go||Demonstrates bucket listing usage, including listing by default parameters and listing by specified parameters|
|bucket_acl.go||Demonstrates how to read/set bucket ACL (Access control)|
|bucket_referer.go||Demonstrates how to set/read/clear bucket whitelist (Anti-leech settings)|
|bucket_logging.go||Demonstrates how to set/read/clear bucket logs (Set access logging)|
|bucket_lifecycle.go||Demonstrates how to set/read/clear lifecycles of objects in the bucket (Manage object lifecycle)|
|bucket_cors.go||Demonstrates how to set/read/clear CORS of the bucket (Cross-origin resource sharing)|